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
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.
- $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:
- $this->Email->send(); //make sure you "send" the email before trying to read the session data
Now, it's easy to find out what those email messages will look like without processing the emails through the Internet.
Cheers,
-Kevin Wentworth
Tags for Viewing Rendered Email Messages in CakePHP
Cakephp | Component | Example | 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 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.