Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rewrite or set the Return-Path in cakePHP Email Component?

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? :)

like image 897
lorem monkey Avatar asked Jan 28 '10 18:01

lorem monkey


1 Answers

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();
like image 159
Simon East Avatar answered Nov 16 '22 02:11

Simon East