PHP邮件标题不起作用?

时间:2016-12-14 18:40:35

标签: php email email-headers

每当我将标题添加到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');

1 个答案:

答案 0 :(得分:3)

更具体地回答您的问题,请参阅http://php.net/manual/en/function.mail.php标题为&#34的示​​例2;示例#2使用额外标题发送邮件。&#34;

您需要为有效标题添加返回/换行。