我一直试图通过将JSON发布到处理实际发送的响应中来使PHP的mail()函数工作.php该响应处理实际发送。经过多次尝试,我仍然无法将消息发送给接收者。我现在遇到的问题是消息需要符合 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");
正如这里建议的那样编辑 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,它只包含字符串值
注意所有''r'n'
的单引号? 和''r'n'n'
这些没有被正确解释/解析,必须用双引号"'r'n"
和"'r'n'n"
括起来。
请参阅手册以了解mail()
:
- http://php.net/manual/en/function.mail.php - 一切都在那里。
手册没有任何地方建议对'r'n
使用单引号,而只对mail('caffeinated@example.com', 'My Subject', $message);
和其他一些例子使用单引号,而不是对'r'n
使用单引号。
- 再次阅读手册。所有
'r'n
周围都有双引号,而不是单引号。
正如Martin在评论中所建议的那样,PHPMailer是一个很好的程序,Swiftmailer也是如此。
引用:
- https://github.com/PHPMailer/PHPMailer PHPMailer
- http://swiftmailer.org/斯威夫特邮件