为什么这个 PHP 错误引用 localhost?
我在本地计算机和办公室的服务器上运行 XAMPP。 两者都是 Windows 机器。
我正在编写一些使用 mail()
从表单发送电子邮件的代码。 默认情况下,它使用 sendmail.exe
(XAMPP 附带)发送电子邮件。 在所有情况下,邮件实际上是通过第三台计算机(即 Exchange 服务器)发送的。
从我的本地机器上,PHP 可以很好地发送邮件。 在服务器上,提交表单后出现此错误:
警告:mail() [function.mail]: 无法连接到邮件服务器 “localhost”端口 25,验证您的 “SMTP”和“smtp___端口”设置 php.ini 或使用 ini_set() 中
... 后跟我的文件名。
我不明白为什么它引用“localhost”。 php.ini 或 sendmail.ini 中没有任何地方使用“localhost” - 我使用邮件服务器的名称。 两台机器上使用的 SMTP 信息是相同的。
据我所知,这两个环境具有所有重要的共同点:
- php.ini 文件是相同的
- sendmail.ini 文件是相同的
- 两台机器都安装了相同版本的 XAMPP
- 相同的批处理脚本将在两台机器上运行并成功通过
sendmail.exe
发送电子邮件
我已多次停止并启动 Apache,以确保它使用更新的配置文件。
当我收到上述错误时,我注意到 sendmail.exe 没有生成任何日志文件,这让我认为它从未运行。
我缺少什么?
已解决
我的问题是我以为它使用的是 c:\xampp\php\php.ini
,但实际上它使用的是 c:\xampp\apache\bin\php.ini
代码>. 这应该是显而易见的,我之前在本地计算机上编辑了正确的文件,但不知何故,在服务器上进行更改时我感到困惑。
使用 php_info() 向我显示了加载了哪个配置文件,并且我编辑了正确的配置文件。 现在正在工作! 感谢大家的帮助。
I'm running XAMPP on my local machine and on a server in the office. Both are Windows machines.
I'm writing some code that uses mail()
to send email from a form. By default, it uses sendmail.exe
(which comes with XAMPP) to send the email. In all cases, the mail is actually sent via a third machine, which is the Exchange server.
From my local machine, PHP can send mail just fine. On the server, upon form submission I get this error:
Warning: mail() [function.mail]:
Failed to connect to mailserver at
"localhost" port 25, verify your
"SMTP" and "smtp___port" setting in
php.ini or use ini_set() in
... followed by my filename.
I don't understand why it's referencing "localhost." Nowhere in php.ini or sendmail.ini does is "localhost" used - I use the name of the mail server. The SMTP information used on both machines is the same.
As far as I can tell, the two environments have everything important in common:
- The php.ini files are identical
- The sendmail.ini files are identical
- Both machines have the same version of XAMPP installed
- The same batch script will run on both machines and successfully send email via
sendmail.exe
I have stopped and started Apache several times to make sure it's using the updated config files.
When I get the error above, I notice that no log file is produced by sendmail.exe, which makes me think it's never run.
What am I missing?
Solved
My problem was that I thought it was using c:\xampp\php\php.ini
, but it was actually using c:\xampp\apache\bin\php.ini
. This should have been obvious, and I had previously edited the correct file on my local machine, but somehow I got confused when making the changes on the server.
Using php_info()
showed me which config file was loaded, and I edited the correct one. It's working now! Thanks everyone for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在页面中添加对
phpinfo()
的调用,并检查:php.ini
SMTP ini 设置(如 phpinfo 表中显示)正确。
You should add a call to
phpinfo()
in your page, and check that:php.ini
SMTP
ini settings (as displayed in the phpinfo tables) are correct.尝试在服务器上的代码中使用它:
Try to use this in the code on server:
我也必须这样做 - 您需要发送 sendmail.ini:
您的 sendmail.ini 应该位于 C:\xampp\sendmail\sendmail.ini 中。
您只需要在这里关心 3 个变量:
详细信息在这里:发送邮件和 xampp
Bill H
I had to do this also - you need to sent up the sendmail.ini:
Your sendmail.ini should be located in C:\xampp\sendmail\sendmail.ini.
You only need to be concern with 3 variables here:
Details are here: Send mail and xampp
Bill H