我有以下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>';
}
?>
访问页面时,我没有收到任何错误,日志文件中的输出如下:
[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
脚本似乎正确执行但我没有收到任何电子邮件。
答案 0 :(得分:0)
将您的邮件发送到try {} catch(e){console.log(e)}中。这样你就可以了解错误