ZF-7008: Method setReturnPath() not working


It seems that the method setReturnPath() is not working as it should and is not overwriting the default path.

Code example:

$reqMail = new Zend_Mail();
$reqMail->setFrom("", "Name");

The result email doesn't have the set ReturnPath.


I looked into this for the past hour and I am now not sure if this is considered a bug or no.

Facts: To have a Sendmail keep the ReturnPath you have to send an additional parameter to the PHP mail function, more precise "" The send() method from Zend/Mail.php doesn't do that as it calls Zend_Mail_Transport_Sendmail with no parameters to be passed to the PHP function mail(). The workaround to this is to create a Zend_Mail_Transport_Sendmail object with the proper parameter before initiating the Zend_Mail object, but this in my view will need you to set the ReturnPath twice, once in the call $tr = new Zend_Mail_Transport_Sendmail(''); and the second time with the setReturnPath("") method from Zend/Mail.php

A better approach would be to change line 949 from the file Zend/Mail.php from: $transport = new Zend_Mail_Transport_Sendmail(); to: if (!empty($this->_returnPath)) $transport = new Zend_Mail_Transport_Sendmail("-f" . $this->_returnPath); else $transport = new Zend_Mail_Transport_Sendmail();

This could have a side effect though...If the user runs PHP in safe_mode() and he calls the method setReturnPath from Zend/Mail.php this will ultimately result in a PHP error due to the addition parameter given to the mail() function.

I am looking for your input on this.

Personally I think setReturnPath() is just wrong on Zend_Mail, it should be a Transport option.

I agree with Benjamin.

I also think _returnPath parameter should be move into parameter of transport.

And it might be better to split Zend_Mail into 3 parts, for example : Zend_Mail_Sender Zend_Mail_Server (it would include transport classes) Zend_Mail_Reader (or _Receiver)

I change this issue into next major.

I don't agree with the separation of names, however we should discuss this on the 2.0 Roadmap, can you add a note on the moving of setReturnPath() to the wiki page?…

So we dont forget it.

Hi, Benjamin, :D Sorry for late comment.

Yes I will add some commment the page in this weekend.

I will close once as document issue.

Soved in SVN trunk r19450