MainelyDesign.com Blog

Viewing Rendered Email Messages in CakePHP

Posted on 12/09/2009 at 12:15 pm by Kevin Wentworth
Viewed 21,139 times | 1 comment

For a while it's bugged me that I wasn't able to see the rendered output of my email messages that are sent using the CakePHP email component. I would change my code to use a remote smtp server but I still had to send messages.  Well, I finally figured out how to "debug" my emails sent using CakePHP.  Thanks to this posting for finally putting all the pieces together...

Set $this->Email->delivery to 'debug'

The first step is to tell the CakePHP Email Component to deliver the message using it's debug method.  This will tell the Email Component to not send the message, but render it and store the results in a session variable.

  1. $this->Email->delivery = 'debug';

Access the value of the Email stored in the Session

The next step is to read the value of the Email Message that CakePHP stored in the session variable.  This is easy, once you know what it's stored as:

  1. $this->Email->send();   //make sure you "send" the email before trying to read the session data
  2. var_dump($this->Session->read('Message.email'));

Now, it's easy to find out what those email messages will look like without processing the emails through the Internet.

Cheers,
-Kevin Wentworth

Bookmark and Share

Tags for Viewing Rendered Email Messages in CakePHP

Cakephp | Component | Example | Usage | Web Programming

Comments for this Posting

Posted by Dr Fox

on 12/12/09

Well done. Although I think the pr() method would be a better option for printing out variables in a neat and readable fashion.

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