开发者

how to send email notification dynamically in cakephp?

I need to send email notification to my client dynamically when i receive any order from client. the email ID should be fetched from the data开发者_运维问答base and should send the mail to that email ID. The text or content for the email Id will be fixed.


From the Cake manual: http://book.cakephp.org/view/1286/Sending-a-basic-message

Create a default.ctp file in /app/views/layouts/email/text called default.ctp containing

<?php echo $content_for_layout; ?>

Create a default.ctp file in /app/views/elements/email/text called new_order.ctp containing

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

Add a function similar to this one to the controller which deals with your orders:

<?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();
}
?>

Call this method when saving a new order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜