[英]CakePHP Paypal IPN Plugin email not working
我在CakePHP應用程序中使用此插件。 除了發送電子郵件外,其他一切似乎都可以正常工作。
我在AppController.php中有以下代碼
function afterPaypalNotification($txnId)
{
//Here is where you can implement code to apply the transaction to your app.
//for example, you could now mark an order as paid, a subscription, or give the user premium access.
//retrieve the transaction using the txnId passed and apply whatever logic your site needs.
$transaction = ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->findById($txnId);
$this->log($transaction['InstantPaymentNotification']['id'], 'paypal');
//Tip: be sure to check the payment_status is complete because failure
// are also saved to your database for review.
if ($transaction['InstantPaymentNotification']['payment_status'] == 'Completed')
{
//Yay! We have monies!
ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
'id' => $txnId,
'subject' => 'Thanks!',
'message' => 'Thank you for the transaction!'
));
}
else
{
//Oh no, better look at this transaction to determine what to do; like email a decline letter.
ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
'id' => $txnId,
'subject' => 'Failed!',
'message' => 'Please review your transaction'
));
}
}
但是從Paypal返回的數據保存在Instant_payment_notifications表中,但是由於某些原因未發送電子郵件。 之前有人嘗試過該插件嗎,電子郵件功能是否起作用?
我需要在app / Config中啟用email.php才能使電子郵件正常工作嗎? 我在Cake網站上的某個地方讀到,我不需要該文件即可運行電子郵件,所以我想這不是問題所在。
任何幫助將不勝感激。
謝謝。
在CakePhp 2.5中,您應該使用CakeEmail
使用類EmailConfig創建文件/app/Config/email.php。 /app/Config/email.php.default包含此文件的示例。
在類聲明之前在/app/Controller/AppController.php中添加以下行
App::uses('CakeEmail', 'Network/Email');
在afterPaypalNotification函數中替換
ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
'id' => $txnId,
'subject' => 'Thanks!',
'message' => 'Thank you for the transaction!'
));
與(快速電子郵件,沒有樣式)
CakeEmail::deliver('customer@example.com', 'Thanks!', 'Thank you for the transaction!', array('from' => 'you@example.com'));
要么
$Email = new CakeEmail();
$Email->template('email_template', 'email_layout')
->emailFormat('html')
->to('customer@example.com')
->from('you@domain.com')
->viewVars(array('id' => $txnId))
->send();
電子郵件模板轉到/app/View/Emails/html/email_template.ctp
電子郵件布局轉到/app/View/Layouts/Emails/html/email_layout.ctp
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.