【问题标题】:PHP mail function is not working after "from" header is added [duplicate]添加“发件人”标头后PHP邮件功能不起作用[重复]
【发布时间】:2020-01-30 12:47:07
【问题描述】:

我正在使用 php 标头发送电子邮件。

$to = 'test@email.com';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$message = '<h1>Test</h1>';

mail($to, $subject, $message, $headers);

此功能运行正常。

但是在我添加了“From”之后,mail() 函数就不起作用了。

$headers .= "From: from@address.com";

有什么想法吗?

【问题讨论】:

  • 最后必须有. "\r\n"
  • 尝试使用 From first 然后 MIME 然后 content type 更改条目的顺序。

标签: php html email


【解决方案1】:

可能你试图欺骗电子邮件,所以它失败了。

在使用 mail() 的同时继续使用 Reply-ToFrom 是很好的做法

$headers .= "From: from@address.com\r\n";
$headers .= "Reply-To: from@address.com\r\n";

但是,个人建议你使用 SMTP 而不是 mail() 或 PHPMailer。

【讨论】:

    猜你喜欢
    • 2013-12-16
    • 2015-12-27
    • 1970-01-01
    • 2012-02-10
    • 2014-05-19
    • 2011-04-07
    • 2012-07-12
    相关资源
    最近更新 更多