PHP mail()函数返回true,但不发送邮件 [英] PHP mail() function returns true, but doesn't send mail

查看:124
本文介绍了PHP mail()函数返回true,但不发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我调用PHP mail()函数时,它返回true。



我检查了我的php.ini(我正在运行CentOS):

  SMTP = localhost 
smtp_port = 25
sendmail_path = / usr / sbin / sendmail -t -i
mail.add_x_header =
/ pre>

我在一个论坛上阅读,我必须安装 sendmail 。所以我安装了现在有一个mail()函数的网站不再加载。所以我删除了sendmail,mail()函数再次返回true,但不发送邮件。



任何想法?

解决方案

要发送电子邮件,您需要一个SMTP服务器(本地或远程)。实际上你的邮件功能只是将邮件传递到您的SMTP服务器,这是真正发送您的邮件的邮件。



在您的php.ini中出现此行

  sendmail_path = usr / sbin / sendmail -t -i 

如果您使用该配置参数(从手册):


如果设置,smtp,smtp_port和sendmail_from被忽略,
指定的命令被执行。


但最重要的是您只需卸载 sendmail ,以便您可以预期邮件无效。我知道sendmail 正在给您一些问题,可能是配置问题,但现在您的php.ini配置是错误的。



如何解决它?




  • 从php.ini开始删除 sendmail_path 参数。


  • 安装简单的配置SMTP服务器,如 postfix


  • 验证postfix在端口22上正在侦听:





netstat -lnt





  • 尝试从您的php mail()函数发送邮件


  • 验证您的邮件是否已正确发送(请查看您的 /var/log/mail.log /var/log/mail/mail.log


  • 您还可以验证邮件不在后缀队列中:





postqueue -f



I know that this question was asked before.

When I call the PHP mail() function, it returns true.

I checked my php.ini (I'v running CentOS):

SMTP = localhost
smtp_port = 25
sendmail_path = /usr/sbin/sendmail -t -i
mail.add_x_header = On

I read in a forum that I have to install sendmail. So I installed it. Now sites with a mail() function doesn't load anymore. So I removed sendmail, and the mail() function returns true again, but doesn't send the mail.

Any idea?

解决方案

To send an email you need a SMTP server (local or remote). Actually your mail function just passes the mail to your SMTP server and is this one which really send your email.

In your php.ini appears this line

sendmail_path = /usr/sbin/sendmail -t -i

You should be aware if you use that configuration parameter (from manual):

If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.

But the most important thing here is you just uninstall sendmail so you can expect your mail goes nowhere. I know sendmail was giving you some problems, possibly configuration problems, but now your php.ini configuration is wrong.

How to solve it?

  • Start removing the sendmail_path parameter from the php.ini.

  • Install a simple to configure SMTP server like postfix.

  • Verify postfix is listening at port 22:

netstat -lnt

  • Try to send a mail from your php mail() function

  • Verify your mail has been sent correctly (check your /var/log/mail.log or /var/log/mail/mail.log files)

  • You also can verify the mail is not in the postfix queue:

postqueue -f

这篇关于PHP mail()函数返回true,但不发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆