php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43348 Mail function returns true but no email sent
Submitted: 2007-11-20 14:58 UTC Modified: 2009-11-24 10:14 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:1 (20.0%)
From: RQuadling at GMail dot com Assigned: scottmac (profile)
Status: Closed Package: Mail related
PHP Version: 5.3CVS-2007-11-20 (snap) OS: Windows XP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2007-11-20 14:58 UTC] RQuadling at GMail dot com
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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-20 16:46 UTC] jani@php.net
It's pretty interesting since nothing has changed in this code between those versions. And using the older one with exactly same line works?
 [2007-11-20 17:04 UTC] RQuadling at GMail dot com
====C:\testmail.php====
<?php
ini_set('SMTP', 'gmail-smtp-in.l.google.com'); // Force GMail to be the server.
$s_Email = 'RQuadling' . '@' . 'GMail.com';
var_dump(mail($s_Email, PHP_VERSION, 'Your message', "From:$s_Email"));
?>

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
 [2007-12-04 08:44 UTC] pipaff at comptrio dot com
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
 [2007-12-04 15:54 UTC] pipaff at comptrio dot com
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
 [2007-12-04 16:50 UTC] RQuadling at GMail dot com
Just to iterate, the mail function for windows in the CVS is broken for CLI, CGI and ISAPI.
 [2008-04-17 14:45 UTC] RQuadling at GMail dot com
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) {
 [2008-04-19 23:59 UTC] nlopess@php.net
a better fix is:
if (!sendmail_path || !*sendmail_path)

let me know if you want me to commit this.
 [2008-04-20 00:49 UTC] scottmac@php.net
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 "".
 [2008-04-22 15:46 UTC] RQuadling at GMail dot com
Nuno, 

if (!sendmail_path || !*sendmail_path)

works for me on 5.3 CVS. Not tested HEAD as I've not got ICU yet.

Richard.
 [2008-07-03 12:53 UTC] danielc@php.net
This needs to be fixed before 5.3 goes out the door.
 [2008-07-04 08:53 UTC] scottmac@php.net
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.


 [2008-07-06 15:22 UTC] jani@php.net
Scott, you had some fix, just commit that, I have no time for this.
 [2008-07-07 21:51 UTC] scottmac@php.net
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.


 [2009-11-24 10:14 UTC] RQuadling at GMail dot com
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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Dec 04 02:03:36 2021 UTC