I’m trying to set up a test email in my controller that outputs the email as it would look, without actually sending the email. I am using CakePHP 2.1
At the top of my controller I have:
App::uses('CakeEmail', 'Network/Email');
And in my controller the method is:
$email = new CakeEmail('default');
$email->from(array('me@example.com' => 'My Site'));
$email->to('you@example.com');
$email->subject('About');
$email->send('My message');
In my email config I have set the $default to Debug mode:
public $default = array(
'transport' => 'Debug',
'from' => 'you@localhost.com',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
How can I output the email? I have scoured Google and have come back with nothing.
Construct the CakeEmail with log enabled:
The following code is an excerpt of the CakeEmail classes send() method, it should be pretty self-explaining.
So your email will end up in that log file.
If you don’t like that feel free to write your own transport class and log to database, session or simply debug() the output in your transport class, do as you like!