Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test an HTML Email Template on CakePHP?

Tags:

cakephp

To confirm a purchase I must send an e-mail to the customer with her shopping cart details. I'd like to test the HTML template to use the appropiate CSS, and of course to check the data that arrives to it. What code should I use instead of setting the Email parameters, to watch how the template will render on the Email?

I'm all new on CakePHP, so your help will be very much appreciated.

Thanks in advance.

~José

like image 339
jsdgdo Avatar asked Sep 19 '12 19:09

jsdgdo


2 Answers

This is CakePHP 1.3, but I have a feeling it may work well with 2.0 as well. While there may be other ways to do it, I do by creating a test action in any controller, then return a render call of the email template. Check this out:

function email_test()
{
    $this->layout = 'email/html/default';
    $user = $this->User->findById(1);
    $this->set('name', $user['User']['firstname']);
    $this->set('email_heading', 'Welcome to My App');
    return $this->render('/elements/email/html/welcome');
}

This action will now render out your email in the browser.

like image 156
Eric Avatar answered Sep 21 '22 17:09

Eric


Use the debug transport for testing.

If you want to make it more comfortable write your own transport that creates a new html file in for example APP/tmp/email/.html See the debug transport class as a reference, it's dead easy to do this http://api20.cakephp.org/view_source/debug-transport#l-34

See also the book -> http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#using-transports

like image 34
floriank Avatar answered Sep 24 '22 17:09

floriank