我正在构建一个 CakePHP 网站,该网站发送如下电子邮件:
$email = new CakeEmail('default');
$email->template('test');
$email->emailFormat('html');
$email->to(array('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9af0f5f2f4c5fef5ffdaffe2fbf7eaf6ffb4f9f5f7" rel="noreferrer noopener nofollow">[email protected]</a>' => 'John Doe'));
$email->subject('Test E-mail');
$email->helpers(array('Html', 'Text'));
$email->viewVars(
array(
...
)
);
if ($email->send()) {
$this->Session->setFlash('The e-mail was sent!', 'default', array('class' => 'alert alert-success'));
}
else {
$this->Session->setFlash('An unexpected error occurred while sending the e-mail.', 'default', array('class' => 'alert alert-error'));
}
除了实际发送电子邮件之外,我还希望能够在变量中捕获电子邮件呈现的 HTML。这样,我可以在数据库中记录电子邮件正文的确切内容。这可行吗?
最佳答案
每line 50 of the MailTransport
class ,看起来实际的 send()
函数返回消息和 header 。所以代替:
if($email->send()) {
尝试:
$mySend = $email->send();
if($mySend) {
//...
那么,$mySend
应该是一个数组:
array('headers' => $headers, 'message' => $message);
关于email - CakePHP 2.1.0 : Capture E-mail Output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9727321/