2011-08-22 71 views
-1

當我收到客戶的任何訂單時,我需要動態地向我的客戶發送電子郵件通知。應該從數據庫中提取電子郵件ID,並將郵件發送到該電子郵件ID。電子郵件ID的文本或內容將被修復。如何在cakephp中動態發送電子郵件通知?

+0

閱讀指南:http://book.cakephp.org/view/1017/Retrieving-Your-Data &http://book.cakephp.org/view/1286/Sending-a-basic-message –

回答

0

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

創建/應用/視圖/佈局/電子郵件/文本包含

<?php echo $content_for_layout; ?> 

創建一個default.thtml中文件default.thtml中文件名爲default.thtml中/應用/視圖/元素/電子郵件/文本稱爲含

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

添加類似這樣的控制器與您的訂單交易功能new_order.ctp:

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

保存新訂單時調用此方法。