MainelyDesign.com Blog

Setting Envelope-From in CakePHP's Email Component

Posted on 03/22/2010 at 05:56 pm by Kevin Wentworth
Viewed 17,353 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:

  1. $this->Email->subject = 'Email Subject';
  2. $this->Email->replyTo = 'email@domain.com';
  3. $this->Email->from = 'Display Name ';
  4. $this->Email->additionalParams = '-f email@domain.com'; //magic
  5. $this->Email->to = 'email@receiver.com';
  6. $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

Bookmark and Share

Tags for Setting Envelope-From in CakePHP's Email Component

Cakephp | Component | Tutorial | Example | Php | Usage | Web Programming

Comments for this Posting

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

Sorry, comments are closed for this posting.

Please Email Kevin if you have any questions. Thanks!

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design