CakePHP Paypal IPN插件电子邮件不工作
我正在CakePHP应用程序中使用插件。除了发送电子邮件,一切似乎都正常 我在AppController.php中有以下代码CakePHP Paypal IPN插件电子邮件不工作,php,cakephp,php-5.5,cakephp-2.5,Php,Cakephp,Php 5.5,Cakephp 2.5,我正在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 subsc
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中,您应该使用 使用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!'
));
使用(快速电子邮件,无样式)
或
电子邮件模板转到/app/View/Emails/html/Email_template.ctp
电子邮件版面转到/app/View/layouts/Email/html/Email_layout.ctp
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();