php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28976 use From: header instead of sendmail_from in php.ini
Submitted: 2004-06-30 18:19 UTC Modified: 2005-01-19 18:41 UTC
Votes:9
Avg. Score:4.9 ± 0.3
Reproduced:9 of 9 (100.0%)
Same Version:1 (11.1%)
Same OS:5 (55.6%)
From: kdaniel at aosepc dot com Assigned:
Status: Closed Package: Mail related
PHP Version: 4.3.6 OS: Windows\Apache
Private report: No CVE-ID:
 [2004-06-30 18:19 UTC] kdaniel at aosepc dot com
Description:
------------
The mail function always sticks in the Return-Path header based on the php.ini setting even though the email address does not correspond with the From header.

There needs to be a way to either disable the Return-Path header from being inserted into the mail headers or the Return-Path should use the From header email address.



Reproduce code:
---------------
$To = "kdaniel@aosepc.com";
$Text = "This is a test.";
$Html = "<H1>This is a test.</H1>";
$Subject = "PHP Mail Test";
$message = "";

$headers = "From: kdaniel@aosepc.com\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"==MIME_BOUNDRY_alt_main_message\"\n\n";
$headers .= "This part of the E-mail should never be seen. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client.";


$message .= "--==MIME_BOUNDRY_alt_main_message\n";
$message .= "Content-Type: text/plain; charset=ISO-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= $Text . "\n\n";
$message .= "--==MIME_BOUNDRY_alt_main_message\n";
$message .= "Content-Type: text/html; charset=ISO-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
$message .= "<HTML><BODY>\n";
$message .= $Html . "\n";
$message .= "</BODY></HTML>\n\n";
$message .= "--==MIME_BOUNDRY_alt_main_message--\n";

mail($To, $Subject, $message, $headers); 


Expected result:
----------------
Microsoft Mail Internet Headers Version 2.0
Received: from server ([ipaddress]) by servername.com with Microsoft SMTPSVC(6.0.3790.0);
	 Wed, 30 Jun 2004 12:16:25 -0400
Date: Wed, 30 Jun 2004 12:16:41 -0500
Subject: PHP Mail Test
To: kdaniel@aosepc.com
From: kdaniel@aosepc.com
X-Mailer: PHP4
X-Priority: 3
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="==MIME_BOUNDRY_alt_main_message"
Return-Path: kdaniel@aosepc.com
Message-ID: <TCOHEPC033sl3xbYiMC00000824@servername.com>
X-OriginalArrivalTime: 30 Jun 2004 16:16:25.0817 (UTC) FILETIME=[9794FC90:01C45EBD]

--==MIME_BOUNDRY_alt_main_message
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

--==MIME_BOUNDRY_alt_main_message
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit


--==MIME_BOUNDRY_alt_main_message--


Actual result:
--------------
You will notice that the Return-Path header uses the php.ini setting and not the From header.


Microsoft Mail Internet Headers Version 2.0
Received: from server ([ipaddress]) by servername.com with Microsoft SMTPSVC(6.0.3790.0);
	 Wed, 30 Jun 2004 12:16:25 -0400
Date: Wed, 30 Jun 2004 12:16:41 -0500
Subject: PHP Mail Test
To: kdaniel@aosepc.com
From: kdaniel@aosepc.com
X-Mailer: PHP4
X-Priority: 3
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="==MIME_BOUNDRY_alt_main_message"
Return-Path: mrn@aosepc.com
Message-ID: <TCOHEPC033sl3xbYiMC00000824@servername.com>
X-OriginalArrivalTime: 30 Jun 2004 16:16:25.0817 (UTC) FILETIME=[9794FC90:01C45EBD]

--==MIME_BOUNDRY_alt_main_message
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

--==MIME_BOUNDRY_alt_main_message
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit


--==MIME_BOUNDRY_alt_main_message--


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-06 15:32 UTC] sniper@php.net
You mean it uses the sendmail_from ini setting?

 [2004-07-21 04:04 UTC] kdaniel at aosepc dot com
Yes, PHP is picking up the sendmail_from ini setting and sticking it into the mime headers as Return-Path.
 [2004-08-06 19:27 UTC] hholzgra@php.net
I'm pretty sure that this header is added by the SMTP mail server and not by PHP itself. PHP first writes the generated headers to
the SMTP stream, followed by any additional_headers you passed to mail(). Any headers following those you passed as additional_headers have been added by the transporting mail server (s). Looks like it is adding the SMPT "MAIL FROM" into Return_Path:
 [2004-08-06 21:39 UTC] kdaniel at aosepc dot com
I don't see how that is possible because there is no way for the mail server to pick up the sendmail_from ini setting.  PHP has to be using it somewhere.  There needs to be a way to disable its use.
 [2004-08-18 23:07 UTC] dv at josheli dot com
using cli PHP 5 and latest snap (php5-win32-200408181430), the extra "From:" header does not seem to work.

test.php:
<?php
mail('test@example.com','subject','body',"From: me@example.com\r\n");
?>

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in C:\dev\quiktests\test.php on line 3
 [2004-08-23 19:02 UTC] joe at inexo dot com
It's not coming from php.ini.
 [2004-08-24 19:53 UTC] dv at josheli dot com
http://marc.theaimsgroup.com/?l=php-dev&m=109286883222906&w=2
 [2004-11-04 16:53 UTC] Charlesk at netgaintechnology dot com
It seems to me that this was thought of but never implemented.  In sendmail.c:

	if (headers) {
		char *pos = NULL;
		size_t i;

		/* Use PCRE to trim the header into the right format */
		if (NULL == (headers = php_win32_mail_trim_header(headers TSRMLS_CC))) {
			*error = W32_SM_PCRE_ERROR;
			return FAILURE;
		}

		/* Create a lowercased header for all the searches so we're finally case
		 * insensitive when searching for a pattern. */
		if (NULL == (headers_lc = estrdup(headers))) {
			efree(headers);
			*error = OUT_OF_MEMORY;
			return FAILURE;
		}
		for (i = 0; i < strlen(headers_lc); i++) {
			headers_lc[i] = tolower(headers_lc[i]);
		}
	}
 
	/* Fall back to sendmail_from php.ini setting */
	if (mailRPath && *mailRPath) {
		RPath = estrdup(mailRPath);
	}
	else if (INI_STR("sendmail_from")) {
		RPath = estrdup(INI_STR("sendmail_from"));
	} else {
		if (headers) {
			efree(headers);
			efree(headers_lc);
		}
		*error = W32_SM_SENDMAIL_FROM_NOT_SET;
		return FAILURE;
	}


I would think that in the if (headers) section there should be some code to set the mailRPath if the From header is found in headers.  That way when it falls into the if (mailRPath && *mailRPath) section it will appropriately assign the from to the return path.  

Can this be fixed soon?

Thanks
Charles
 [2005-01-02 15:48 UTC] alexhuang at anet dot net dot tw
Please try to make a copy of "c:\winnt\php.ini" to "c:\php".

After I copied the file, no more error messages.
 [2005-01-19 18:41 UTC] sniper@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.

Address passed as "From:" in headers is now used if sendmail_from is empty.

 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 03:02:48 2014 UTC