使用CakePHP插件中的电子邮件模板

时间:2011-05-16 16:06:58

标签: email cakephp plugins

我有一个正在发送电子邮件的CakePHP Shell脚本。该脚本包含在CakePHP插件(foo)中。

将电子邮件模板设置为

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

不起作用,电子邮件发送成功,但电子邮件只是说

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

我已经确认模板已正确命名并且确实存在。

次要说明:

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

如果模板已移至/path_to_app/app/views/elements/email/html/foo/email_template_name.ctp 它确实工作正常。但是,我希望尽可能多地将其作为自包含的电子邮件发送,包括插件本身的模板。

4 个答案:

答案 0 :(得分:4)

您需要告诉CakeEmail插件的名称。 (Cake 2.0.x)

在您的模型中

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

或控制器

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

您需要为电子邮件创建视图:

Plugin/Foo/View/Emails/html/email_template_name.ctp
Plugin/Foo/View/Emails/text/email_template_name.ctp

答案 1 :(得分:1)

请将您的所有代码发布到$ this->电子邮件。

检查:

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

你试过吗

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

并将模板移至

/path_to_app/app/views/elements/email/html/email_template_name.ctp

答案 2 :(得分:1)

再次检查你的路径!

我遇到了同样的问题,我意识到我已将模板放在: /path_to_app/app/plugins/my_plugin_name/views/elements/email/my_template.ctp

但正确的道路是: /path_to_app/app/plugins/my_plugin_name/views/elements/email/html/my_template.ctp

因为我在我的控制器上使用'html'值作为“sendAs”

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

答案 3 :(得分:1)

在cakephp 1.3中没有实现这个功能。 您将在新鲜的cakephp 2.0.0版本中获得它 http://bakery.cakephp.org/articles/lorenzo/2011/10/16/cakephp_2_0_released

因为bug已经修复: http://cakephp.lighthouseapp.com/projects/42648/tickets/1743-cakeemail-in-plugins-doesnt-work-well-with-views

您最终可能会在1.3中询问或提供后退。我不知道cakephp后缀策略和补贴。