如何在cakephp中动态发送电子邮件通知?

时间:2011-08-22 12:09:26

标签: cakephp

当我收到客户的任何订单时,我需要动态地向我的客户发送电子邮件通知。应从数据库中提取电子邮件ID,并将邮件发送到该电子邮件ID。电子邮件ID的文本或内容将被修复。

1 个答案:

答案 0 :(得分:0)

从蛋糕手册:http://book.cakephp.org/view/1286/Sending-a-basic-message

在名为default.ctp的/ app / views / layouts / email / text中创建一个default.ctp文件,其中包含

<?php echo $content_for_layout; ?>

在名为new_order.ctp的/ app / views / elements / email / text中创建一个default.ctp文件,其中包含

Dear <?php echo $user['User']['firstname'] ?>,
Thank you for your order.

向控制器添加与此类似的功能,以处理您的订单:

<?php
function _sendNewUserMail($id) {
    $User = $this->User->read(null,$id);
    $this->Email->to = $User['User']['email'];
    $this->Email->subject = 'Order Confirmation';
    $this->Email->replyTo = 'support@example.com';
    $this->Email->from = 'Cool Web App <app@example.com>';
    $this->Email->template = 'new_order';
    $this->set('User', $User);
    $this->Email->send();
}
?>

保存新订单时调用此方法。