问题
I'm using the cakePHP email component for sending mails from my application. Now the return-path has something like www@domain.tld
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? :)
回答1:
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 = 'name@example.com';
http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Email.html
回答2:
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' => 'myaddress@mydomain.com',
// But in some sendmail configurations (esp. on cPanel)
// you have to pass the -f parameter to sendmail, like this
'additionalParameters' => '-fmyaddress@mydomain.com',
...
);
}
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('myaddress@mydomain.com')
// Haven't tested this next line, but may possibly work?
->config(array('additionalParameters' => '-fmyaddress@mydomain.com'))
->send();
回答3:
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.
回答4:
To change the return path in CakePHP Email component I do like this:
...
$return_path_email = 'return@email.com';
...
$this->Email->additionalParams = '-f'.$return_path_email;
and it works like charm ;)
回答5:
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 = 'name@tld.com';
来源:https://stackoverflow.com/questions/2156716/how-to-rewrite-or-set-the-return-path-in-cakephp-email-component