Windows 上的 PHP mail():没有错误,电子邮件未发送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1606086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP mail() on Windows: no errors, the email isn't sent
提问by Alex Ciminian
I'm currently trying to debug an Elgg-based website (I didn't develop it) and I would like to send the emails directly from local development machine (WinXP). I'm running WAMP with Apache 2.2.11 and PHP 5.3.0
我目前正在尝试调试基于 Elgg 的网站(我没有开发它),我想直接从本地开发机器 (WinXP) 发送电子邮件。我正在使用 Apache 2.2.11 和 PHP 5.3.0 运行 WAMP
After some searching, the simplest solution that I've come across is using fake sendmailto forward it to my GMail/Google apps account via SMTP and let it do the sending. The problem is that I get no errors whatsoever, but the email isn't being sent.
经过一番搜索,我遇到的最简单的解决方案是使用虚假的 sendmail通过 SMTP 将其转发到我的 GMail/Google 应用程序帐户并让它进行发送。问题是我没有收到任何错误,但没有发送电子邮件。
Here's what I did:
这是我所做的:
- Copied the sendmail.exe and sendmail.ini to a subfolder in WAMP
- Configured it via sendmail.ini (the configuration settings are ok)
- Edited php.ini to add the path to sendmail.exe
sendmail_path = "C:\Program Files\wamp\bin\sendmail\sendmail.exe -t"
- Commented out the windows SMTP settings in php.ini
; SMTP = localhost
; smtp_port = 25
; sendmail_from = [email protected]
; mail.force_extra_parameters =
- 将 sendmail.exe 和 sendmail.ini 复制到 WAMP 中的子文件夹
- 通过sendmail.ini进行配置(配置设置没问题)
- 编辑 php.ini 以添加 sendmail.exe 的路径
sendmail_path = "C:\Program Files\wamp\bin\sendmail\sendmail.exe -t"
- 在 php.ini 中注释掉 windows SMTP 设置
; SMTP = localhost
; smtp_port = 25
; sendmail_from = [email protected]
; mail.force_extra_parameters =
The mail.log file shows the following:
mail.log 文件显示以下内容:
mail() on [C:\Program Files\wamp\www\mail.php:9]: To: xxx --
Headers: From: xxx Reply-To: xxx X-Mailer: PHP/5.3.0
My guess is that the problem is that the default Windows option (to specify the server and not the sendmail utility) is not overriden. In phpinfo()
I still get the SMTP -> localhost
and smtp_port -> 25
options, even though I commented them.
我的猜测是问题在于默认的 Windows 选项(指定服务器而不是 sendmail 实用程序)没有被覆盖。在phpinfo()
我仍然得到SMTP -> localhost
和smtp_port -> 25
选项,即使我评论了它们。
If anyone managed to get this working, I'd really appreciate some help. In my opinion, using fake sendmail is a lot simpler than installing a mail server on your machine.
如果有人设法让这个工作,我真的很感激一些帮助。在我看来,使用伪造的 sendmail 比在您的机器上安装邮件服务器要简单得多。
Thanks!
谢谢!
P.S. Please don't suggest PHPMailer and the like, because I have touse the mail() function. That's how Elgg works.
PS请不要推荐PHPMailer之类的,因为我要使用mail()函数。这就是埃尔格的工作方式。
采纳答案by Alex Ciminian
I've gotten it to work eventually. The problem was that PHP had a bugin parsing .ini files with spaces in the path (for sendmail). It was fixed in version 5.3.0, but the manual had no info on this.
我终于让它工作了。问题是PHP在解析路径中带有空格的 .ini 文件时有一个错误(对于 sendmail)。它在 5.3.0 版本中得到修复,但手册中没有这方面的信息。
So, yes, it is possible to use sendmail with PHP on Windows :D.
所以,是的,可以在 Windows 上使用带有 PHP 的 sendmail :D。
Thank you all for your time!
谢谢大家的时间!
回答by jerjer
Make sure you have SMTP Service running on your local machine and that SMTP Port(25) is opened.
确保您的本地计算机上运行了 SMTP 服务,并且 SMTP 端口 (25) 已打开。
Have a check on the services (Run->services.msc) and look for Send Mail Transfer
检查服务 (Run->services.msc) 并查找 Send Mail Transfer
If you cannot find SMTP on the services list, you must install it: To add, Run->appwiz.cpl->Add Remove Windows components->IIS->Details->SMTP
如果在服务列表中找不到SMTP,则必须安装它:添加,运行->appwiz.cpl->添加删除Windows组件->IIS->详细信息->SMTP
回答by Sabeen Malik
I am not sure if this helps or not, what i used to do in these scenarios was to setup , outlook on my machine and have it set to get emails from the pop every 5 mins or so, that way my ip/machine was authenticated against the pop and if i just set the :
我不确定这是否有帮助,我过去在这些场景中所做的是在我的机器上设置、展望,并将其设置为每 5 分钟左右从弹出窗口获取电子邮件,这样我的 ip/机器就通过了身份验证反对流行音乐,如果我只是设置:
SMTP = localhost
smtp_port = 25
in php.ini , the mail function worked fine. So in your case just set your outlook to work with a pop and use that smtp in php.ini and hopefully it should work. I havent tested this will GMail though.
在 php.ini 中,邮件功能运行良好。因此,在您的情况下,只需将您的 Outlook 设置为使用 pop 并在 php.ini 中使用该 smtp,希望它可以工作。不过,我还没有测试过这会是 GMail。
回答by VolkerK
P.S. Please don't suggest PHPMailer and the like, because I have to use the mail() function. That's how Elgg works.
PS请不要推荐PHPMailer之类的,因为我要使用mail()函数。这就是埃尔格的工作方式。
...unless you're using a plugin that changes this behaviour:
http://community.elgg.org/pg/plugins/costelloc/read/16498/phpmailer
...除非你使用一个插件来改变这种行为:http:
//community.elgg.org/pg/plugins/costelloc/read/16498/phpmailer