Recent Posts
- (09/10) Fixing Warning: the ECDSA host key for 'github.com' differs from the key for the IP addressTAGS:Web Server Admin
- (12/26) CakePHP 3 - Getting List of Column Definitions from a Table (like schema())TAGS:CakephpCake3
- (09/14) Change Order of Loaded Behaviors in CakePHP 3TAGS:Cake3CakephpWeb ProgrammingPhp
- (05/29) CakePHP 3 - Accept JSON Header Only Working When Debug FalseTAGS:Web ProgrammingCakephpCake3
- (05/23) Remove All Events from Google Calendar (Reset Calendar)TAGS:Web ProgrammingPhp
- (11/08) Google Tag Manager (GTM) Not Firing Default PageView EventTAGS:Web ProgrammingJavascriptGoogle Tag Manager
- (10/13) In PHP, how do you get __toString() Magic Method Result without calling echo?TAGS:CakephpCake3Cakephp 13PhpWeb Programming
- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
Subscribe to my feed
MainelyDesign.com Blog
Setting Envelope-From in CakePHP's Email Component
Posted on 03/22/2010 at 05:56 pm by Kevin Wentworth
Viewed 18,021 times | 1 comment
I've setup a form that allows customers to sign up for an email newsletter and receive a coupon. I wanted to be able to track the bounced messages in case a legitimate customer's coupon was bounced for whatever reason. As I've learned, setting up the "return-path" for an email message isn't as simple as setting $this->Email->return = 'email@domain.com'; You have to use an as yet undocumented feature... $this->Email->additionalParams;
Making PHP mail() include your return-path email address
If you want bounce messages, you have to update the email headers used to send mail from your server. If you read the CakePHP documentation on the Email Component, you'll see that it mentions using $this->Email->return. This "works" but most often your webserver will strip out the return-path header and add in its own. I use cPanel and it does is by default.
No matter what I do, the return-path is nobody @ somedomain.com
This is because you need to send an additional parameter to PHP's mail function that tells it to overwrite sendmail's headers. This is how you would do this using the CakePHP email component, using $this->additionalParams:
- $this->Email->subject = 'Email Subject';
- $this->Email->replyTo = 'email@domain.com';
- $this->Email->from = 'Display Name ';
- $this->Email->additionalParams = '-f email@domain.com'; //magic
- $this->Email->to = 'email@receiver.com';
- $this->Email->send();
The above code will set the envelope-from header, which in my case also changed the return-path header.
By setting the envelop-from header, you'll change the return-path header
After looking at my headers and using $this->Email->additionalParams, I noticed that the return-path was updated too!
Cheers,
-Kevin Wentworth
Tags for Setting Envelope-From in CakePHP's Email Component
Cakephp | Component | Tutorial | Example | Php | Usage | Web Programming
Comments for this Posting
Sorry, comments are closed for this posting.
Please Email Kevin if you have any questions. Thanks!
Posted by Daniel K
on 2/9/10
I remember using that from the old days before I got into cakephp. How could I have forgotten. Thanks for jogging my memory!
www.intrit.com