【发布时间】:2017-04-30 05:01:55
【问题描述】:
每当我将标题添加到mail() 时,收件人都不会收到任何电子邮件。
这工作正常:
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('contact@xxx.net', 'My Subject 2', $message);
这样不行:
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send with headers
mail('contact@xxx.net', 'My Subject', $message, 'From: Test <test123@yahoo.co.uk>');
有什么想法吗?
编辑:
这似乎是由@yahoo.co.uk 电子邮件地址引起的。 @gmail.com 没问题!
为什么!???这与我的生产服务器有关吗??
编辑 2:
即使我使用PHPMailer,也会发生同样的事情:
// Include Composer autoloader.
require_once __DIR__ . '/vendor/autoload.php';
$mail = new PHPMailer;
$mail->setFrom('test123@yahoo.co.uk', 'Mailer');
$mail->addAddress('contact@xxx.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
但它适用于@gmail.com:
$mail->setFrom('test123@gmail.com', 'Mailer');
【问题讨论】:
-
我知道这不是您确切问题的答案,但是您是否考虑过使用现有的库(例如 PHPMailer)来为您解决这个问题?
-
您是否从 PHP 或您的操作系统日志(如 syslog)中收到错误?这可能会告诉你原因。
-
我没有从 PHP 中得到任何错误。我在我的服务器上看不到任何错误日志 - 它是共享主机。
-
PHPMailer 默认使用
mail函数。测试是设置 yahoo smtp (github.com/PHPMailer/PHPMailer) 以检查您的主机服务器(默认 PHP 邮件配置)是否被 yahoo 阻止。
标签: php email email-headers