我的PHP表单验证未发送电子邮件

时间:2019-06-19 21:08:38

标签: php validation recaptcha

我有一个html表单,我正在php中进行表单验证,验证是否选中了Google Recaptcha,然后发送电子邮件。 我找不到什么错,但是代码可以正常工作,因为它将您带回到您提交表单的页面。但是电子邮件没有发送。

我的HTML表单

<?php
//Checking For reCAPTCHA
$captcha;
if (isset($_POST['g-recaptcha-response'])) {
    $captcha = $_POST['g-recaptcha-response'];
}
// Checking For correct reCAPTCHA
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LeaDKkUAAAAANJa7frEZ087HF7TfKytUIcqNpwP&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
if (!$captcha || $response.success == false) {
    header('location: ' . $_SERVER['HTTP_REFERER']);
} else {
/* Check all form inputs using check_input function */
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

 if( isset($_POST) ){    
    //user sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date_sent = date('d/m/Y');
    $time = date('H:i:s');

    //form data
    $name = check_input($_POST['name']);
    $email = check_input($_POST['email']);
    $numpeople = check_input($_POST['numpeople']);            
    $arrivalDate = check_input($_POST['arrivalDate']);
    $departureDate = check_input($_POST['departureDate']);
    $cabin = check_input($_POST['cabin']);
    $message = check_input($_POST['comment']);


    //send email if all is ok
    $headers = "From: opeturmo@opeturmo.com" . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    $emailbody = "<h2>Booking - Reservas</h2>
                  <p><strong>Nombre: </strong> {$name} </p>
                  <p><strong>Email: </strong> {$email} </p>
                  <p><strong>numpeople: </strong> {$numpeople} </p>
                  <p><strong>arrivalDate: </strong> {$arrivalDate} </p>
                  <p><strong>arrivalDate: </strong> {$arrivalDate} </p>
                  <p><strong>cabin: </strong> {$cabin} </p>
                  <p><strong>Message: </strong> {$message} </p>

                  <p>This message was sent from the IP Address: {$ipaddress} on {$date_sent} at {$time}</p>";

               mail ("natashanodine@gmail.com","Formulario Web",$emailbody,$headers);
               //redirect back to form
    header('location: ' . $_SERVER['HTTP_REFERER']);

        }   


}

?>

我的php contact_form.php验证

cout <<

0 个答案:

没有答案