9
votes

I'm using the cakePHP email component for sending mails from my application. Now the return-path has something like [email protected]

How can I set or rewrite the Return-Path value in emails when using the cakePHP Component?

I know how to do it when sending mails via 'mail' in PHP but the cakePHP email component seems to missing such a feature... or am I missing something? :)

5
My problem with the $this->Email->return = [email protected] was that it was rewritten by postfix when sending via mail/default. I had to send my mails via smtp, where the return is also not working - but: it gets replcaed with the sender/from. Does anyone has clue why postfix rewrites the return-path? The cake debug does show the alternated return-path setting. - lorem monkey

5 Answers

8
votes

In CakePHP 2 (where the Email Component is largely replaced by the CakeEmail class), you can do this configuration inside /app/Config/email.php:

class EmailConfig {
    public $email = array(
        ...
        // The next line attempts to create a 'Return-path' header
        'returnPath' => '[email protected]',

        // But in some sendmail configurations (esp. on cPanel)
        // you have to pass the -f parameter to sendmail, like this
        'additionalParameters' => '[email protected]',
        ...
    );
}

Or if you need to do it just for a single email, something like this should work...

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('MyConfig');
$email->from(...)
      ->to(...)
      ->subject(...)
      ->returnPath('[email protected]')
      // Haven't tested this next line, but may possibly work?
      ->config(array('additionalParameters' => '[email protected]'))
      ->send();
4
votes

There's an attribute called EmailComponent::return that is the return path for error messages. Note that this is different than the replyTo attribute.

$this->Email->return = '[email protected]';

http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Email.html

3
votes

A co-worker and I were working on this same issue, we found that editing the following line in php.ini gave us our fix:

from:

sendmail_path = /usr/sbin/sendmail -t -i

to:

sendmail_path = /usr/sbin/sendmail -t -i -f youremail@address

when testing be sure to send your emails to a valid domain. this caught us for a few minutes.

2
votes

To change the return path in CakePHP Email component I do like this:

...
$return_path_email = '[email protected]';
...

$this->Email->additionalParams = '-f'.$return_path_email;

and it works like charm ;)

0
votes

Digging into the cake manual when you were looking at how to use the rest of the component you should have seen something like the following. This is what set the Return-Path.

$this->Email->return = '[email protected]';