mail cannot be delivered in PHP even SMTP server is running and PHP mail() returns true

梦想与她 提交于 2019-12-11 08:11:34

问题


I am trying to use PHP to send a simple mail. I have tried to use telnet to check whether Mercury is running, and it replys yes. Also mail() returns true, therefore my scripts should be okay, however mail still can not be sent, what may be the cause of this problem?

Here is my PHP code:

$subject = "Simple mail";
$message = "Here is a test mail";
$to = "me@gmail.com";
$from = "me@test.com";
$header = "From: ".$from;

if(mail($to, $subject, $message, $header))
   print "success<br>";
else
   print "fail<br>";

Below is my PHP.ini:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = localhost
; smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost  

; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.  

; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
sendmail_path = "C:\mailtodisk\mailtodisk.exe"

; 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 = Off

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\php\logs\php_mail.log"

So if the mail server is running correctly, and the scripts are right, then the only problem causes mail cannot be delivered should be the mails have never arrived the server, then what can I do to find out where is the error and solve it?

I have followed the important notice to make some changes.


回答1:


In your XAMPP you are using "C:\mailtodisk\mailtodisk.exe" instead of a mail server. It writes all mails in the C:\xampp\mailoutput folder, not sending them to internet.



来源:https://stackoverflow.com/questions/11645329/mail-cannot-be-delivered-in-php-even-smtp-server-is-running-and-php-mail-retur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!