[英]CakePHP Paypal IPN Plugin email not working
I'm using this plugin in a CakePHP Application. 我在CakePHP应用程序中使用此插件。 Everything seems to work except sending emails.
除了发送电子邮件外,其他一切似乎都可以正常工作。
I have the following code in AppController.php 我在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'
));
}
}
But the data returned from Paypal is saved in the instant_payment_notifications table but for some reason the emails are not sent. 但是从Paypal返回的数据保存在Instant_payment_notifications表中,但是由于某些原因未发送电子邮件。 Has anybody tried this plugin before and did the email fonctionality work?
之前有人尝试过该插件吗,电子邮件功能是否起作用?
Do I need to enable email.php in app/Config for the emails to work? 我需要在app / Config中启用email.php才能使电子邮件正常工作吗? I read somewhere on Cake's website that I don't need that file for emails to work, so I guess that's not where the problem is.
我在Cake网站上的某个地方读到,我不需要该文件即可运行电子邮件,所以我想这不是问题所在。
Any help will be appreciated. 任何帮助将不胜感激。
Thanks. 谢谢。
In CakePhp 2.5 you should use CakeEmail 在CakePhp 2.5中,您应该使用CakeEmail
Create the file /app/Config/email.php with the class EmailConfig. 使用类EmailConfig创建文件/app/Config/email.php。 The /app/Config/email.php.default has an example of this file.
/app/Config/email.php.default包含此文件的示例。
Add following line in /app/Controller/AppController.php before class declaration 在类声明之前在/app/Controller/AppController.php中添加以下行
App::uses('CakeEmail', 'Network/Email');
In afterPaypalNotification function replace 在afterPaypalNotification函数中替换
ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
'id' => $txnId,
'subject' => 'Thanks!',
'message' => 'Thank you for the transaction!'
));
with (fast e-mail, no style) 与(快速电子邮件,没有样式)
CakeEmail::deliver('customer@example.com', 'Thanks!', 'Thank you for the transaction!', array('from' => 'you@example.com'));
or 要么
$Email = new CakeEmail();
$Email->template('email_template', 'email_layout')
->emailFormat('html')
->to('customer@example.com')
->from('you@domain.com')
->viewVars(array('id' => $txnId))
->send();
Email template goes to /app/View/Emails/html/email_template.ctp 电子邮件模板转到/app/View/Emails/html/email_template.ctp
Email layouts goes to /app/View/Layouts/Emails/html/email_layout.ctp 电子邮件布局转到/app/View/Layouts/Emails/html/email_layout.ctp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.