Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-不接收电子邮件_Php_Json - Fatal编程技术网

PHP-不接收电子邮件

PHP-不接收电子邮件,php,json,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 =

因此,我不确定我在这里做错了什么,但应该发生的是,一旦输入得到满足,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);
}

?> 

检查您的日志和/或垃圾邮件。另外,从本地机器运行?托管站点?PHP/mail是否已安装并正在运行?错误?列表还在继续…切换到其他主机。明白了,伙计!谢谢,我甚至没有检查我所在的测试环境。我疯狂地修改代码。说我的车轮打滑!不客气,干杯