PHP mail() function return true but no message
I have a simple PHP script to send email to localhost with mercury mail server and read it with Mozilla Thunderbird. And it’s work.
And then, I upgarde XAMPP version to 1.8.1 and my function return true but no email delivered.
I tried to send email with Thunderbird to root@localhost.com and it work.
So iI try to change mail function in php.ini to this but not work
[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 = root@localhost.com ; 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:\xampp\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" I try to change sendmail.ini to this but not work ; configuration for fake sendmail ; if this file doesn't exist, sendmail.exe will look for the settings in ; the registry, under HKLM\Software\Sendmail [sendmail] ; you must change mail.mydomain.com to your smtp server, ; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup) ; emails delivered via IIS's pickup directory cause sendmail to ; run quicker, but you won't get error messages back to the calling ; application. smtp_server=localhost ; smtp port (normally 25) smtp_port=25 ; SMTPS (SSL) support ; auto = use SSL for port 465, otherwise try to use TLS ; ssl = alway use SSL ; tls = always use TLS ; none = never try to use SSL smtp_ssl=auto ; the default domain for this server will be read from the registry ; this will be appended to email addresses when one isn't provided ; if you want to override the value in the registry, uncomment and modify ;default_domain=mydomain.com ; log smtp errors to error.log (defaults to same directory as sendmail.exe) ; uncomment to enable logging error_logfile=error.log ; create debug log as debug.log (defaults to same directory as sendmail.exe) ; uncomment to enable debugging ;debug_logfile=debug.log ; if your smtp server requires authentication, modify the following two lines auth_username= auth_password= ; if your smtp server uses pop3 before smtp authentication, modify the ; following three lines. do not enable unless it is required. pop3_server= pop3_username= pop3_password= ; force the sender to always be the following email address ; this will only affect the "MAIL FROM" command, it won't modify ; the "From: " header of the message content force_sender= ; force the sender to always be the following email address ; this will only affect the "RCTP TO" command, it won't modify ; the "To: " header of the message content force_recipient= ; sendmail will use your hostname and your default_domain in the ehlo/helo ; smtp greeting. you can manually set the ehlo/helo name if required hostname=
Best Solution
If mail returns true, then php’s job is done. it’s handed the email over to your outgoing mail server. You need to check that server’s logs to see what happens from that point forward.
e.g. PHP’s role in sending an email is basically the equivalent of taking an envelope you hand it, walking down to the street corner, and dropping it into the mailbox. After that, PHP’s done and it can report success.
If that mailbox gets nailed by a drunk driver and the mail gets destroyed, that’s not PHP’s fault. If the mail gets picked up and sent to a postal sorting facility and then gets lost, that’s also not PHP’s problem.
So go check your mail server’s logs. If it can’t deliver the mail, it’ll report why. If it DID deliver the mail to the destination server, it’ll report so, and then you need to find out why the receiving server isn’t doing its job — maybe your email is getting flagged as spam and dump in the trash.
Related Solutions
Jenkins – How to set the Sender’s address in Jenkins
Jenkins uses the System Admin e-mail address as the sender address for e-mail notification. You can configure this under Manage Jenkins -> Configure System. This is under the Jenkins Location header on that page! It is not immediately obvious that this setting is tied to the e-mail notification settings, since it is not under the E-mail notification header on the configuration page.
Php – Send email from localhost running XAMMP in PHP using GMAIL mail server
Here’s the link that gives me the answer:
[Modify] the php.ini file to use it (commented out the other lines): [mail function] ; For Win32 only. ; SMTP = smtp.gmail.com ; smtp_port = 25 ; For Win32 only. ; sendmail_from = @gmail.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
(ignore the «Unix only» bit, since we actually are using sendmail)
You then have to configure the «sendmail.ini» file in the directory where sendmail was installed:
[sendmail] smtp_server=smtp.gmail.com smtp_port=25 error_logfile=error.log debug_logfile=debug.log auth_username= auth_password= force_sender=@gmail.com
To access a Gmail account protected by 2-factor verification, you will need to create an application-specific password. (source)
Php mail true no email
Description: ------------ Same script working on PHP 4.4.7-dev (cgi-fcgi) (built: Mar 25 2007 21:02:43) PHP 5.2.2RC2-dev (cli) (built: Apr 18 2007 08:03:01) but not on PHP 5.3.0-dev (cli) (built: Nov 20 2007 08:19:12) Using Wireshark to see SMTP activity. No errors, warnings or notices produced. Script doesn't crash. True is returned. Running via the command line to remove all extensions and relying on default configuration. Obviously, you will need to change the SMTP server and email addresses to see this in operation. Reproduce code: --------------- php -n -r "ini_set('SMTP', 'gmail-smtp-in.l.google.com'); var_dump(mail('RQuadling@GeeWhizzMail.com', 'Subject', 'Message', 'From:RQuadling@GeeWhizzMail.com'));" Expected result: ---------------- True AND an email to be received. Actual result: -------------- True but no SMTP activity when monitored using WireShark.
Patches
Pull Requests
History
It's pretty interesting since nothing has changed in this code between those versions. And using the older one with exactly same line works?
====C:\testmail.php==== and then C:\PHP4\PHP -n C:\testmail.php I get 4.4.7-dev message C:\PHP5\PHP -n C:\testmail.php I get nothing. V:\PHP5.2.2RC2-dev\PHP -n C:\testmail.php I get 5.2.2RC2-dev message Today, we made a change from McAfee AV to Symantec AV. I am getting little alerts for PHP4 and the PHP5.2.2 messages going out, but nothing for PHP5.3.0-dev
The title caught my eye right away. PHP 5.2.4 as DSO fails to work properly (Apache 2.0.61) $mail = mail("admin@recipient.com","test","test inside","From: webmaster@sender.com"); if($mail)< print "true"; >else < print"false"; >Expected: "true" and an email to be received (or false without email) Actual: "true", but no email received, no error message/log, no record in MTA (exim) Recently Changed: CGI to DSO, same code worked prior using same PHP/Apache version
Update: Switched back to CGI and mail works again. lost the ability to 'except users' from safe_mode in Apache config (php_admin_value/flag), but mail works. This is on a Linux box CentOS4. 2.6.9 kernel
Just to iterate, the mail function for windows in the CVS is broken for CLI, CGI and ISAPI.
Hi. I have finally managed to get php to compile for windows (yippee for me). So I can now try and get mail() working again. The issue is that in ext/standard/mail.c (/* $Id: mail.c,v 1.87.2.1.2.7.2.3 2007/12/31 07:17:15 sebastian Exp $ */), line 197, the test of . if (!sendmail_path) always evaluates to false when there is no sendmail_path which would be the case on windows. The next line differentiates between processing for windows/netware and everything else. If the test is if(0 == strlen(sendmail_path)) then that would work. The INI_STR call in Line 194 always returns a string if the directive is known (doesn't need to be set, just has to exist as a directive). So, I've attached a patch which I have compiled and tested on Windows. This is in relation to bug http://bugs.php.net/bug.php?id=43348 Index: mail.c =================================================================== RCS file: /repository/php-src/ext/standard/mail.c,v retrieving revision 1.87.2.1.2.7.2.3 diff -u -u -r1.87.2.1.2.7.2.3 mail.c --- mail.c 31 Dec 2007 07:17:15 -0000 1.87.2.1.2.7.2.3 +++ mail.c 17 Apr 2008 14:40:33 -0000 @@ -194,7 +194,7 @@ char *sendmail_path = INI_STR("sendmail_path"); char *sendmail_cmd = NULL; - if (!sendmail_path) < + if (0 == strlen(sendmail_path)) < #if (defined PHP_WIN32 || defined NETWARE) /* handle old style win smtp sending */ if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE)a better fix is: if (!sendmail_path || !*sendmail_path) let me know if you want me to commit this.Nuno I posted about the underlying change that broke this to internals last week. It's potentially broken in more places that relied on INI_STR to turn NULL as it now returns "".Nuno, if (!sendmail_path || !*sendmail_path) works for me on 5.3 CVS. Not tested HEAD as I've not got ICU yet. Richard.This needs to be fixed before 5.3 goes out the door.This is a regression caused by http://bugs.php.net/bug.php?id=42657 Check in was http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_ini.c?r1=1.39.2.2.2.18.2.6&r2=1.39.2.2.2.18.2.7 It affects any place that relied on INI_STR to return NULL for the original value.Scott, you had some fix, just commit that, I have no time for this.This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better.To everyone who runs the test script - please change the email address you are using as I am getting your test results. It is certainly reassuring to know that PHP is A-OK, but for you, not getting the message in your mailbox . well, probably not so good. For the stats, I probably get 2 or 3 a week.