PHP - 没有收到电子邮件

时间:2014-07-02 16:17:48

标签: php json

所以我不确定我在这里做错了什么,但应该发生的事情是,一旦输入得到满足,JSON就会向我的模态联系表单返回一条确认消息,说明它是成功的, PHP将发送电子邮件。我收到确认,但从未收到电子邮件。有什么建议吗?

<?php 

$to = "name@domain.com";
$subject = "Design Inquiry";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

$body = <<<EOD
<b>Contact Info</b>
<hr>
Name: $name<br>
Phone: $phone<br>
Email: $email<br>
Details: $message
EOD;

sleep(2);

$name       = ($_POST['name']);
$phone      = ($_POST['phone']);
$email      = ($_POST['email']);
$message    = ($_POST['message']);
$reg_exp    = "^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$^";
$error      = '';

if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message']) ) {

    if (!empty($_POST['name'])) {
        $name = trim(stripslashes(htmlspecialchars($_POST['name'])));
    } else {
        $name = NULL;
        $error .= "<p>Please enter your name.</p>";
    }

    if (preg_match($reg_exp, $email)) {
        $email = trim(stripslashes(htmlspecialchars($_POST['email'])));
    } else {
        $name = NULL;
        $error .= "<p>Please enter a valid email address.</p>";
    }

    if (!empty($_POST['message'])) {
        $message = trim(stripslashes(htmlspecialchars($_POST['message'])));
    } else {
        $message = NULL;
        $error .= "<p>Please enter a message or question.</p>";
    }

    if (!empty($error)) {
        $return['error'] = true;
        $return['msg'] = "<h4>The request was successful but your form is not filled out correctly.</h4>".$error;                   
        echo json_encode($return);
        exit();
    } else {                          
        $return['error'] = false;
        $return['msg'] = "<p><span class='glyphicon glyphicon-ok'></span> <strong>Thank you! You will be contacted shortly.</strong></p>"; 
        echo json_encode($return);
        mail($to, $subject, $body, $headers);
    }       

} else {
    $return['error'] = true;
    $return['msg'] = "<h5>There was a problem with your submission. Please try again.</h5>";    
    echo json_encode($return);
}

?> 

0 个答案:

没有答案