简体   繁体   English

PHP mail()函数没有返回错误 - 没有收到电子邮件

[英]PHP mail() function not returning errors - no email received

I have the following PHP script to test mail() functionality: 我有以下PHP脚本来测试mail()功能:

<?php
    echo `whoami`;
    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    $name = 'John';
    $email = 'j@example.com';
    $message = 'My message';
    $verify = '4';
    $to = 'youremailaddress@somedomain.com';
    $subject = 'Enquiry';
    $headers = 'From: j@example.com' . "\r\n" .
                            'Reply-To: j@example.com' . "\r\n" .
                            'MIME-Version: 1.0' . "\r\n" .
                            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
                            'X-Mailer: PHP/' . phpversion();

    if (1 == 1)
    {
            if (mail($to, $subject, $message, $headers))
            {
                    echo '<p>Sucess</p>';
            }
            else
            {
                    echo '<p>Something went wrong</p>';
            }
    }
    else
    {
            echo '<p>Submit not clicked</p>';
    }
?>

Upon accessing the page I receive no errors, the output in the log file is as follows: 访问页面时我没有收到任何错误,日志文件中的输出如下:

[20-Jan-2017 00:07:25 America/New_York] mail() on [/var/www/html/contact/contact.php:20]: To: youremailaddress@somedomain.com -- Headers: From: j@example.com  Reply-To: j@example.com  MIME-Version: 1.0  Content-type: text/html; charset=iso-8859-1  X-Mailer: PHP/5.6.29-0+deb8u1

The script appears to execute correctly but I do not receive any email. 脚本似乎正确执行但我没有收到任何电子邮件。

put your mail sending logic inside try{} catch(e){ console.log(e) } . 把你的邮件发送到try {} catch(e){console.log(e)}里面。 So that you will come to know about error 这样你就会知道错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM