简体   繁体   English

PHP Mail()函数头

[英]PHP Mail() Function Headers

OK, so I have a PHP mail function. OK,所以我有一个PHP邮件功能。 It works fine when I put it on my server but when I put I mail it to my client so he can put it on his server it doesn't work. 当我将其放在服务器上时,它可以正常工作,但是当我将其邮寄给我的客户时,他可以将其放在他的服务器上,它不起作用。 It doesn't give me any errors on their server and gets to the "Thanks" page just fine but never really sends the email. 它不会给我他们服务器上的任何错误,并且可以很好地进入“谢谢”页面,但从未真正发送过电子邮件。 They say it's because PHP Mail does not have the right headers but I didn't think that it needed headers if it was just simply "mail(to, subject, message)" They say they have all PHP related functions set properly because I initially thought it was PHP Mail being turned off. 他们说这是因为PHP Mail没有正确的标头,但我认为如果只是简单地“ mail(to,subject,message)”就不需要标头,因为我最初设置了所有与PHP相关的功能,以为是PHP Mail被关闭了。

Any suggestions would be great. 任何建议都很好。

PHP's mail function is a piece of garbage. PHP的邮件功能是一个垃圾。 If it says true, it only means the email was handed off from PHP to the local mailserver. 如果它是true,则仅表示电子邮件已从PHP传递到本地邮件服务器。 It does NOT mean the email was actually delivered. 这并不意味着电子邮件已实际发送。 In real world terms, mail() stuffs your envelope into the mailbox on the corner, then starts proudly saying "I did it! I delivered it to your user!"... with the envelope still stuck inside the mailbox. 用现实的术语来说,mail()将信封塞进角落的邮箱中,然后开始自豪地说:“我做到了!我已经将它交付给您的用户了!”……信封仍然停留在邮箱中。

Your client should check his mail server's logs to see what's happening with the email once it's handed off from PHP. 您的客户端应检查其邮件服务器的日志,以查看从PHP移交后的电子邮件情况。 Even if the mail itself gets bounced or spam-trashed later, PHP's mail function will NEVER see any of those errors. 即使邮件本身后来被退回或被垃圾邮件处理,PHP的邮件功能也永远不会看到任何这些错误。

You should always be using a "FROM" header. 您应该始终使用“ FROM”标头。

Note: 注意:

When sending mail, the mail must contain a From header. 发送邮件时,邮件必须包含“发件人”标头。 This can be set with the additional_headers parameter, or a default can be set in php.ini. 可以使用Additional_headers参数设置此参数,也可以在php.ini中设置默认值。

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. 未能执行此操作将导致类似警告的错误消息:php.ini中未设置mail():“ sendmail_from”或自定义“ From:”标头丢失。 The From header sets also Return-Path under Windows. Windows下的From标头还设置了Return-Path。

This is straight from the documentation for mail() 这直接来自mail()的文档

In my experience, I've almost always had better luck setting up a dedicated mail account for the client in their domain on their mail server and authenticating with the mail server and sending mail through it using SMTP via PEAR_Mail. 以我的经验,我总是比较幸运的是,在他们的邮件服务器上为其域中的客户端设置了专用的邮件帐户,并通过邮件服务器进行身份验证并通过PEAR_Mail使用SMTP通过它发送邮件。 You'll get much more useful information from PEAR_Mail if something goes wrong in the sending process, plus by sending via SMTP via the mail server you have a better chance of avoiding issues with SPF, etc. 如果在发送过程中出现问题,您将从PEAR_Mail获得更多有用的信息,此外,通过邮件服务器通过SMTP发送邮件,您更有可能避免SPF等问题。

确保在服务器上安装了邮件传输代理,例如sendmail。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM