【发布时间】:2016-07-02 05:54:08
【问题描述】:
我一直试图通过将 JSON 发布到处理实际发送的 response.php 来使 PHP 的 mail() 函数工作。经过多次尝试,我仍然无法将消息传递给接收者。我现在遇到的问题是消息需要符合 RFC 5322:
wouter0.7@live.nl
host mx2.hotmail.com [65.54.188.72]
SMTP error from remote mail server after end of data:
550 5.7.0 (BAY004-MC1F14) Message could not be delivered. Please ensure the message is RFC 5322 compliant.
脚本的消息输出为:
asdada\r\n\nName: Www\r\nEmail: wouter0.7@live.nl
(请记住,经过一千次尝试后,我只是按了几个按钮,因此该消息没有意义。) 我使用PHP Manual:MAIL() 上的示例来创建标题,所以它们看起来像这样:
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
当我查看从邮件传递系统收到的邮件时,标题似乎是有序的。但是,消息似乎在此过程中变得混乱,导致邮件传递失败。
有谁知道为什么会发生这种情况?如果我需要上传更多代码/示例,请告诉我。
编辑:忘了提到我已经尝试向 mail() 函数添加第五个参数:
mail($to,$subject,$message,$headers,"-f your@email.here");
如建议here 编辑 2:我用于 mail() 函数的代码:
//Send Mail
$to = "wouter0.7@live.nl"; // Your email here
$path = $_SERVER['HTTP_HOST'];
$subject = 'Message from ' . $path; // Subject message here
$email = $return["email"];
//Set headers
$headers = 'From: ' . $email .''. '\r\n'.
'Reply-To: '.$email.'' . '\r\n' .
'X-Mailer: PHP/' . phpversion();
$message = $return['msg'] . '\r\n\n' .'Name: '.$return['name']. '\r\n'
.'Email: '.$return['email'];
mail($to, $subject, $message, $headers,"-f wouter0.7@live.nl");
$return 数组用于编码为 JSON,它只包含字符串值
【问题讨论】:
-
您需要发布完整或更多代码。代码不够。向我们展示“你”在使用什么。
-
mail一点都不好,我建议不要使用 PHPMailer 来解决这个问题:github.com/PHPMailer/PHPMailer