【发布时间】:2025-12-15 21:35:01
【问题描述】:
我将 PHP 邮件脚本从 Apache 服务器移动到 Nginx 服务器的根文件夹(Ubuntu 12.0.4 LTS、MySQL、PHP5-FPM)。该表单在 Apache 服务器上运行良好,但是,在 nginx 服务器上,当我尝试发送邮件时,我收到一条错误消息。
phpinfo() 返回有关邮件设置的以下详细信息:
php-fpm - active
mail.add_x_header - On
mail.force_extra_parameters - no value
mail.log - no value
sendmail_from - no value
sendmail_path - /usr/sbin/sendmail -t -i
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 =
/var/log/mail.log 声明如下:
Jan 27 10:11:49 localhost sendmail[22457]: My unqualified host name (localhost) unknown; sleeping for retry
Jan 27 10:12:49 localhost sendmail[22457]: unable to qualify my own domain name (localhost) -- using short name
Jan 27 10:12:50 localhost sendmail[22457]: gethostbyaddr(192.241.186.7) failed: 1
Jan 27 10:12:50 localhost sendmail[22457]: gethostbyaddr(10.128.248.128) failed: 1
Jan 27 10:12:50 localhost sendmail[22457]: alias database /etc/mail/aliases rebuilt by root
Jan 27 10:12:50 localhost sendmail[22457]: /etc/mail/aliases: 4 aliases, longest 10 bytes, 66 bytes total
Jan 27 10:12:50 localhost sm-mta[22516]: My unqualified host name (localhost) unknown; sleeping for retry
Jan 27 10:12:52 localhost sm-msp-queue[22521]: My unqualified host name (localhost) unknown; sleeping for retry
Jan 27 10:13:50 localhost sm-mta[22516]: unable to qualify my own domain name (localhost) -- using short name
Jan 27 10:13:50 localhost sm-mta[22516]: gethostbyaddr(192.241.186.7) failed: 1
Jan 27 10:13:50 localhost sm-mta[22516]: gethostbyaddr(10.128.248.128) failed: 1
Jan 27 10:13:50 localhost sm-mta[22523]: starting daemon (8.14.4): SMTP+queueing@00:10:00
Jan 27 10:13:52 localhost sm-msp-queue[22521]: unable to qualify my own domain name (localhost) -- using short name
Jan 27 10:14:10 localhost sendmail[22542]: My unqualified host name (localhost) unknown; sleeping for retry
Jan 27 10:15:10 localhost sendmail[22542]: unable to qualify my own domain name (localhost) -- using short name
Jan 27 10:15:10 localhost sendmail[22542]: s0RFFAmY022542: from=www-data, size=423, class=0, nrcpts=1, msgid=<201401271515.s0RFFAmY022542@$
Jan 27 10:15:10 localhost sm-mta[22546]: s0RFFAC7022546: from=<www-data@localhost>, size=638, class=0, nrcpts=1, msgid=<201401271515.s0RFF$
Jan 27 10:15:10 localhost sendmail[22542]: s0RFFAmY022542: to=example@outlook.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00$
Jan 27 10:15:11 localhost sm-mta[22548]: s0RFFAC7022546: to=<example@outlook.com>, ctladdr=<www-data@localhost> (33/33), delay=00:00:01, $enter code here
这是否表明我的服务器上未正确设置 PHP Mail()?
非常感谢您的建议。
【问题讨论】:
-
疑难解答101:阅读你得到的错误信息,看看他们指向的代码。
-
我只收到脚本内部消息“错误”:
if(mail($address, $e_subject, $msg, $headers)) { // Email has sent successfully, echo a success page. echo "<fieldset>"; echo "<div id='success_page'>"; echo "<h1>Email Sent Successfully.</h1>"; echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>"; echo "</div>"; echo "</fieldset>"; } else { echo 'ERROR!'; }