Recent Posts
- (10/14) Forcing A Single Join in CakePHP PaginationTAGS:CakephpCakephp 13DatabaseErrorsHabtmMysqlMssqlWeb ProgrammingUsage
- (08/11) Inserting NOW() into MySQL Using CakePHPTAGS:CakephpDatabaseMysqlMssqlWeb ProgrammingUsage
- (08/07) Best PaginateCount for CakePHP - with Group By SupportTAGS:CakephpBehaviorsWeb ProgrammingUsageDatabaseExampleMysqlHabtmHack
- (04/03) CakePHP Error Messages Not Showing on FormTAGS:CakephpCakephp 13Web ProgrammingErrorsUsage
- (02/06) Sorting Paginated Results Using a Related Model Field in CakePHPTAGS:CakephpWeb ProgrammingUsageExample
- (11/02) Changing CakePHP's Model useTable on the FlyTAGS:CakephpWeb ProgrammingMysqlDatabaseExampleTutorial
- (10/18) The Funniest Error Message Ever - Thank You EclipseTAGS:EclipseWeb ProgrammingErrorsHumorWindowsUsageSoftwarePhpCakephp
- (09/27) Upgrading CakePHP Application to 1.3 (from 1.2)TAGS:CakephpUpgrade
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 2,875 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

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