CakeEmail - 手动发送HTML和纯文本消息

时间:2012-07-19 16:23:15

标签: php cakephp

我想使用内置函数从CakePHP发送纯文本和HTML电子邮件,但不要触及.ctp文件。

这是我想要的CakeEmail:

//Send email to user
$email = new CakeEmail('default');
$email->to($customers['Customer']['email']);
$email->subject('Password reset');
$email->htmlMessage('<div>Reset the password</div>');
$email->textMessage('Password the reset');
$email->send();

但显然,这些功能不存在,所以任何人都知道另一种解决方案吗? 我不想触摸CakePHP的Email文件夹,因为电子邮件布局&amp;内容是动态生成的。

Cake version 2.0.6

基本上,我想要这个代码的CakePHP版本:http://www.daniweb.com/web-development/php/threads/2959/sending-htmlplain-text-emails 能够发送HTML和纯文本电子邮件

1 个答案:

答案 0 :(得分:2)

其实非常简单。 我这样做(用html文本):

$this->Email->emailFormat('both');

$text = trim(strip_tags($html));
$this->Email->viewVars(compact('text', 'html'));

if ($this->Email->send()) {...}

你只需要在相应的视图ctps中回显变量

相关问题