Text to appear in the email $fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message', 'department' => 'Department'); // Success and error alerts $okMessage = 'We have received your inquiry. Stay tuned, we’ll get back to you very soon.'; $errorMessage = 'There was an error while submitting the form. Please try again later'; // SMTP settings $smtpUse = false; // Set to true to enable SMTP authentication $smtpHost = ''; // Enter SMTP host ie. smtp.gmail.com $smtpUsername = ''; // SMTP username ie. gmail address $smtpPassword = ''; // SMTP password ie gmail password $smtpSecure = 'tls'; // Enable TLS or SSL encryption $smtpAutoTLS = false; // Enable Auto TLS $smtpPort = 587; // TCP port to connect to // reCAPTCHA settings $recaptchaUse = false; // Set to true to enable reCAPTHCA $recaptchaSecret = 'YOUR_SECRET_KEY'; // enter your secret key from https://www.google.com/recaptcha/admin /* * LET'S DO THE SENDING */ // if you are not debugging and don't need error reporting, turn this off by error_reporting(0); error_reporting(E_ALL & ~E_NOTICE); try { if(count($_POST) == 0) throw new \Exception('Form is empty'); if($recaptchaUse == true) { require('recaptcha/src/autoload.php'); if (!isset($_POST['g-recaptcha-response'])) { throw new \Exception('ReCaptcha is not set.'); } $recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret, new \ReCaptcha\RequestMethod\CurlPost()); // we validate the ReCaptcha field together with the user's IP address $response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); if (!$response->isSuccess()) { throw new \Exception('ReCaptcha was not validated.'); } } $emailTextHtml .= "
$fields[$key] | $value |
---|