php – mail()无法在新服务器上运行

前端之家收集整理的这篇文章主要介绍了php – mail()无法在新服务器上运行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
可能是一个愚蠢的问题,但我找不到PHP邮件功能不起作用的原因
我有一个关于debian挤压的Nginx服务器,我最近搬到了它.我尝试过简单的邮件执行,但它返回false.
  1. if(mail('test@email.com','test-subject','test-text-blablabla'))
  2. echo 'ok';
  3. else
  4. echo 'bad';

我该怎么办?

谢谢.

我在PHP.ini的邮件部分:

  1. [mail function]
  2. ; For Win32 only.
  3. ; http://PHP.net/smtp
  4. SMTP = localhost
  5. ; http://PHP.net/smtp-port
  6. smtp_port = 25
  7.  
  8. ; For Win32 only.
  9. ; http://PHP.net/sendmail-from
  10. ;sendmail_from = me@example.com
  11.  
  12. ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
  13. ; http://PHP.net/sendmail-path
  14. ;sendmail_path =
  15.  
  16. ; Force the addition of the specified parameters to be passed as extra parameters
  17. ; to the sendmail binary. These parameters will always replace the value of
  18. ; the 5th parameter to mail(),even in safe mode.
  19. ;mail.force_extra_parameters =
  20.  
  21. ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
  22. mail.add_x_header = On
  23.  
  24. ; The path to a log file that will log all mail() calls. Log entries include
  25. ; the full path of the script,line number,To address and headers.
  26. ;mail.log =
好的,我做到了.我如何使用Nginx服务器进行debian压缩:(我从root用户执行的所有命令)

首先,您需要安装sendmail

  1. apt-get install sendmail

接下来,您必须配置比我想象的更容易的文件

  1. sendmailconfig

好吧,我制作的下一步是PHP.ini配置(我不是一个很棒的管理员,我是初学者,所以我不知道是否有必要.)

我设置

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

好的,从这一刻起,理论上,您可以发送电子邮件,但对于我的情况,它导致504 http错误网关超时.但正如我后来发现的那样,电子邮件已经发送到电子邮箱.
所以,我的测试PHP文件是:

  1. <?PHP
  2. mail('myWorkingEmail@example.com','test','you done that');
  3. echo 'ok'; // I use this to check that script is end the execution
  4. ?>

这很清楚.

下一个问题是504错误.我去了日志文件

  1. nano /var/log/mail.log

在这里我发现这个错误(这不是唯一的一个错误,但是那个错误导致了504错误):

  1. sm-msp-queue[***]: My unqualified host name (myhostname) unknown; sleeping for retry

然后,找到我如何解决这个麻烦:
http://forums.fedoraforum.org/archive/index.php/t-85365.html最后评论页面.

或者我说的另一个词:

  1. nano /etc/hosts

在该文件中,我更改了主机的顺序

  1. 127.0.0.1 my_ip localhost myhostname

保存,完成.打开你的测试PHP文件,没有任何504错误和电子邮件是你在邮件功能中提到的电子邮件的收入.正如我所说,我是一个新手,这可能不适合你,但无论如何它对我有用.当然,这不是最终配置.希望你觉得它有用.

猜你在找的PHP相关文章