繁体   English   中英

CakePHP Paypal IPN插件电子邮件不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM