【问题标题】:CakeEmail - Send HTML and Plain-text message manuallyCakeEmail - 手动发送 HTML 和纯文本消息
【发布时间】:2012-07-18 21:23:21
【问题描述】:

我想使用内置函数从 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 文件夹,因为电子邮件的布局和内容是动态生成的。

蛋糕版 2.0.6

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

【问题讨论】:

标签: php cakephp


【解决方案1】:

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 2014-04-09
    • 2016-08-10
    • 2018-02-09
    • 2020-12-12
    • 2019-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多