mail()在新服务器上不起作用 [英] mail() doesn't work on new server

查看:140
本文介绍了mail()在新服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我该怎么办?





我的php.ini邮件部分:

  [邮件功能] 
;仅适用于Win32
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

;仅适用于Win32
; http://php.net/sendmail-from
; sendmail_from = me@example.com

;仅适用于Unix您也可以提供参数(默认值:sendmail -t -i)。
; http://php.net/sendmail-path
; sendmail_path =

;强制添加要作为额外参数
传递的指定参数;到sendmail二进制文件。这些参数将始终代替
的值; mail()的第五个参数,即使在安全模式下。
; mail.force_extra_parameters =

;添加X-PHP起始脚本:这将包括脚本的uid,后跟文件名
mail.add_x_header = On

;将记录所有mail()调用的日志文件的路径。日志条目包括
;脚本的完整路径,行号,地址和标题。
; mail.log =


解决方案

我做到了。如何使用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','你这样做');
echo'ok'; //我用这个来检查脚本是否结束执行
?>

这很清楚。



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

  nano /var/log/mail.log 

这里我发现这个错误(不是唯一的一个错误,但是那个负责504错误):

  sm-msp-queue [***]:我的不合格的主机名(myhostname)未知;睡觉重试

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



或另一个字我做到这一点:

  nano / etc / hosts 

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

  127.0.0.1 my_ip localhost myhostname 

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


May be it's a dumb question, but I can't find the reason why php mail function doesn't work I have a nginx server on debian squeeze, I moved to it recently. I tried simple mail execution but it return false.

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

What can i do with it?

Thanks.

my mail section of 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 =

解决方案

Okay, I made it. How I made it for debian squeeze with nginx server: (all commands I execute from root user)

First of all you need to install sendmail

apt-get install sendmail

next, you must configure this file that was easier than I thought

sendmailconfig 

okay, next step that I make was a php.ini configuration (I'm not a great admin, I'm a beginner, so I don't know is it necessary or not.)

I set

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

Okay, from this moment, theoretically, you can send email, but for my case it led to 504 http error gateway time-out. But as I found much later the email already came to email box. So, my test php file is:

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

That's pretty clear.

Next problem is 504 error. I go to the log files

nano /var/log/mail.log

and here i find this error (that not the only one error, but that one is responsible for 504 error):

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

Then, to find how I can solve this trouble: http://forums.fedoraforum.org/archive/index.php/t-85365.html last comment on that page.

Or another words I made this:

nano /etc/hosts

and in that file I change the order of the hosts

127.0.0.1 my_ip localhost myhostname 

save, done. open your test php file, there is no any 504 error and emails is income to email you mention in mail function. As I say, I'm a novice, and that may not work for you, but it work for me anyhow. This is not the end configuration, of course. Hope you find it helpful.

这篇关于mail()在新服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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