ZF-8988: Zend Mail Transport SMTP set sender email address

Issue Type: Bug Created: 2010-01-28T04:35:44.000+0000 Last Updated: 2011-10-19T15:03:22.000+0000 Status: Resolved Fix version(s): - 1.11.1 (30/Nov/10)

Reporter: Stefan Straakenbroek (souldude) Assignee: Marc Hodgins (mjh_ca) Tags: - Zend_Mail

Related issues: - ZF-7008

Attachments: - ZF-8988.patch


File: /Zend/Mail/Transport/Smtp.php Line: 207

In the smtp transport the from address is set with the following function:

// Set sender email address $this->_connection->mail($this->_mail->getFrom());

When sending a mail to an unknown user with a valid host. In most cased the headers will be read and the Return-Path header will be used to return the mail.

When sending a mail to a non-existing host. The smtp server will return the mail to the from address given in the smpt transport. The header has not been read.

In my opinion the sender email address must be set with the following function, so the bounce addresses goes to the return path.

// Set sender email address $this->_connection->mail($this->_mail->getReturnPath());

Which automatically fallback in the from address if return path is not set.


Posted by Ilan Rivers (ilanr) on 2010-01-29T01:40:54.000+0000

Funny that this was created yesterday. I recently had the same problem on a project I am working on. This should really be as simple as changing the function that is called. Hope that this fix can be included in the next mini release.

Posted by Stefan Straakenbroek (souldude) on 2010-02-01T01:03:11.000+0000

I saw the issue ZF-7008 but that one is using the php mail function:

"Sending mail with an additional command line parameter."

In my case i use the SMTP transport.

$transport = new Zend_Mail_Transport_Smtp('');

Because of that, i cannot use the function described in zend manual:

$transport = new Zend_Mail_Transport_Sendmail('');

Posted by Andy Thompson (at465) on 2010-03-27T06:26:19.000+0000

I also agree that the MAIL FROM should be able to be overridable (either as a transport option or by interpretting the $mail->getReturnPath).

This is commonly used to forward bounces to another email address for processing, whilst allowing manually replied messages go back to the From address.

The Reply-To header isn't an option in these cases, as the bounce address might have additional information such as user id to be used to identify the non-existant email address for automatic unsubscription, and unnessary for the receiver to see the information (which clients seeing Reply-To, will also display the From).

Since sendmail supports setting this return path, please can the smtp class?

Posted by Andy Thompson (at465) on 2010-03-28T13:11:54.000+0000

Please read regarding Return-Path

ZF-195 originally added this feature

ZF-8273 was incorrect, it was not a bug, and was what broke #ZF-195 and caused this issue.

The Return-Path is what is set in transit by the MAIL FROM, and any Return-Path header sent to Smtp is stripped. The From mail header gives the user the friendly reply address even when MAIL FROM is different.

Posted by Andy Thompson (at465) on 2010-04-28T13:40:01.000+0000

To clarify, I believe this is a regression bug caused by ZF-8273 breaking Smtp Return-Path support, affecting ZF 1.9.6 onwards. (edited to correct version number)

Here is a patch to fix it.

Posted by Andy Thompson (at465) on 2010-04-28T15:17:13.000+0000

I was asked on irc to include a unit test for this, so I've added a test to the SmtpTest, and included a mock SMTP protocol class needed for it, which fails before the patch and succeeds after.

Posted by Satoru Yoshida (satoruyoshida) on 2010-06-09T00:24:16.000+0000

Sorry, I have been inactive since last April.

Posted by Marc Hodgins (mjh_ca) on 2010-11-06T02:39:47.000+0000

Agreed, the behavior introduced by ZF-8273 is incorrect. The RFC 2821 states that both the MAIL FROM and the Return-Path header should be the same value:

<pre class="literal">
The first step in the procedure is the MAIL command.

      MAIL FROM: [SP  ] 

... and ...

<pre class="literal">
 The time stamp line and the return path line are formally defined as

Return-path-line = "Return-Path:" FWS Reverse-path 

Andy, there are a couple of problems with your proposed patch. It doesn't run unless the TESTS_ZEND_MAIL_SMTP_ENABLED constant is set to true, which isn't necessary because this can be tested offline. Also the calls to addBcc(), addCc(), etc, aren't necessary to test this.

So, I'm attaching a simplified patch which includes a test that runs by default.

Posted by Marc Hodgins (mjh_ca) on 2010-11-22T14:52:22.000+0000

Applied to trunk in r23423, merged to 1.11 release branch in r23424

Posted by Steffen Weber (steffen) on 2011-10-19T15:03:22.000+0000

The same bug exists in Zend Framework 2.0 Beta 1. Could you please fix it there, too?

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.