8

可能这是一个愚蠢的问题,但我找不到php邮件功能不起作用的原因我在debian挤压上有一个nginx服务器,我最近搬到了它。我尝试了简单的邮件执行,但它返回错误。

if(mail('test@email.com', 'test-subject', 'test-text-blablabla'))
   echo 'ok';
else
   echo 'bad';

我能用它做什么?

谢谢。

我的 php.ini 邮件部分:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com 

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
4

1 回答 1

24

好的,我做到了。我如何使用 nginx 服务器进行 debian 挤压:(我从 root 用户执行的所有命令)

首先你需要安装sendmail

apt-get install sendmail

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

sendmailconfig 

好的,下一步我要做的是 php.ini 配置(我不是一个优秀的管理员,我是初学者,所以我不知道是否有必要。)

我设置

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

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

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

这很清楚。

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

nano /var/log/mail.log

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

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

然后,找到解决这个问题的方法: http ://forums.fedoraforum.org/archive/index.php/t-85365.html该页面上的最后一条评论。

或者我做了这个:

nano /etc/hosts

在那个文件中我改变了主机的顺序

127.0.0.1 my_ip localhost myhostname 

保存,完成。打开您的测试 php 文件,没有任何 504 错误,并且电子邮件是您在邮件功能中提到的电子邮件的收入。正如我所说,我是一个新手,这可能对你不起作用,但无论如何它对我有用。当然,这不是最终配置。希望对您有所帮助。

于 2013-02-15T00:40:52.323 回答