0
1

<?php
if($_POST)
{
require('constant.php');

    $user_name      = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
    $user_email     = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
    $user_phone     = filter_var($_POST["phone"], FILTER_SANITIZE_STRING);
    $content   = filter_var($_POST["content"], FILTER_SANITIZE_STRING);

    if(empty($user_name)) {
        $empty[] = "<b>Name</b>";       
    }
    if(empty($user_email)) {
        $empty[] = "<b>Email</b>";
    }
    if(empty($user_phone)) {
        $empty[] = "<b>Phone Number</b>";
    }   
    if(empty($content)) {
        $empty[] = "<b>Comments</b>";
    }

    if(!empty($empty)) {
        $output = json_encode(array('type'=>'error', 'text' => implode(", ",$empty) . ' Required!'));
        die($output);
    }

    if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation
        $output = json_encode(array('type'=>'error', 'text' => '<b>'.$user_email.'</b> is an invalid Email, please correct it.'));
        die($output);
    }

    //reCAPTCHA validation
    if (isset($_POST['g-recaptcha-response'])) {

        require('component/recaptcha/src/autoload.php');        

        $recaptcha = new ReCaptchaReCaptcha(SECRET_KEY, new ReCaptchaRequestMethodSocketPost());

        $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);

          if (!$resp->isSuccess()) {
                $output = json_encode(array('type'=>'error', 'text' => '<b>Captcha</b> Validation Required!'));
                die($output);               
          } 
    }

    $toEmail = "myemail@gmail.com";
    $mailHeaders = "From: " . $user_name . "<" . $user_email . ">rn";
    if (mail($toEmail, "Contact Mail", $content, $mailHeaders)) {
        $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .', thank you for the comments. We will get back to you shortly.'));
        die($output);
    } else {
        $output = json_encode(array('type'=>'error', 'text' => 'Unable to send email, please contact'.SENDER_EMAIL));
        die($output);
    }
}
?>

|
  • 2

1

0

 $mail_body        = $content;
   $mail_body       .= "rnrnName: ".$user_name; //sender name
   $mail_body       .="rnE-Mail: ".$user_email; //sender email
   $mail_body       .="rnPhone: ".$user_phone; //sender phone
   $mail_body       .="rnrn";


if (mail($toEmail, "Contact Mail", $mail_body, $mailHeaders)) {
|