- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
- (06/12) View Layer - Getting count of Entities in View in Cakephp 3TAGS:CakephpCake3
- (05/23) Changing URL in beforeRedirect() in Component - Cakephp 3TAGS:CakephpCake3Web Programming
- (01/28) Foundation CSS Framework ResourcesTAGS:FoundationCss
- (01/27) Change View File from Controller in CakePHP 3TAGS:CakephpCake3UsageWeb Programming
- (01/13) Loading Model/Table Anywhere in Cake3TAGS:Cake3Cakephp
- (10/06) CURL PHP 5.5 Issue on Windows (Using Twilio SDK)
Subscribe to my feed
Setting Envelope-From in CakePHP's Email Component
Posted on 03/22/2010 at 05:56 pm by Kevin Wentworth
Viewed 11,884 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@example.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 = 'firstname.lastname@example.org';
- $this->Email->from = 'Display Name ';
- $this->Email->additionalParams = '-f email@example.com'; //magic
- $this->Email->to = 'firstname.lastname@example.org';
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!