How to check HTML email template on CakePHP?

To confirm the purchase, I must send an email to the customer with information about her basket. I would like to test the HTML template to use the appropriate CSS, and, of course, check the data that comes into it. What code should be used instead of setting up email settings to see how the template will be displayed in email?

I'm all new on CakePHP, so your help would be greatly appreciated.

Thanks in advance.

~ Jose

+6
source share
4 answers

This is CakePHP 1.3, but I feel it can work well with 2.0 too. Although there may be other ways to do this, I do by creating a test action in any controller, and then return a call to render the email template. Check this:

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 display your email in the browser.

+10
source

Use debug tracing for testing.

If you want to make it more convenient, write your own transport that creates a new html file, 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 book → http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#using-transports

+1
source
  $this->Email->to = $user_id_array[0]['User']['email']; $this->Email->subject = $arrTemplate[0]['EmailTemplate']['subject']; $this->Email->replyTo = 'Admin< admin@indianic.com >'; $this->Email->from = 'Admin< admin@indianic.com >'; $this->Email->sendAs = 'html'; $this->Email->template = '/elements/email/html/warning_message'; $this->set('email_message',$arrTemplate[0]['EmailTemplate']['body']); $this->Email->send(); 

this way you can set the email template

+1
source

Here is a simple way that I use to display the html / plain text content of the email content in the browser that I want to send using the email class cakephp ie App::uses('CakeEmail', 'Network/Email'); . Just exit at the end of the email template file or (email layout file), and then try sending the email. It will provide email content.

NTN.

+1
source

Source: https://habr.com/ru/post/925794/


All Articles