Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use an Email Template from a CakePHP Plugin

I have a CakePHP Shell Script that's sending an email. This script is contained in a CakePHP plugin (foo).

Setting the Email Template as

$this->Email->template = "foo/email_template_name";

Does not work, the email sends successfully, however the email just says

Not Found: /path_to_app/app/views/elements/email/html/foo/email_template_name.ctp

I have verified that the template is named correctly and does exist.

Minor Notes:

$this->Email->sendAs = "both";

If the template is moved to /path_to_app/app/views/elements/email/html/foo/email_template_name.ctp it does work correctly. However I was hoping to ship this as much as possible as a self contained email including the templates in the plugin itself.

like image 489
Justin Yost Avatar asked May 16 '11 16:05

Justin Yost


2 Answers

You need to tell CakeEmail the name of the Plugin. (Cake 2.0.x)

In your Model

$email = new CakeEmail();
$email->template('Foo.email_template_name');

or Controller

$this->email->template('Foo.email_template_name');

You need to create the views for the email:

Plugin/Foo/View/Emails/html/email_template_name.ctp
Plugin/Foo/View/Emails/text/email_template_name.ctp
like image 70
Eskil Mjelva Saatvedt Avatar answered Sep 20 '22 07:09

Eskil Mjelva Saatvedt


Please post all your code for $this->Email.

Check:

$this->Email->sendAs = 'html';

Have you tried

$this->Email->template = "email_template_name";

and moving the template to

/path_to_app/app/views/elements/email/html/email_template_name.ctp
like image 45
Mike Avatar answered Sep 19 '22 07:09

Mike