2016-03-03 8 views
0

Я использую плагин this в приложении CakePHP. Кажется, что все работает, кроме отправки писем.CakePHP Paypal IPN Plugin email не работает

У меня есть следующий код в 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, но по какой-то причине письма не отправляются. Кто-нибудь пробовал этот плагин раньше, и работала ли электронная почта?

Нужно ли мне включить email.php в приложении/Config для работы электронной почты? Я где-то читал на веб-сайте Cake, что мне не нужен этот файл для работы с электронной почтой, поэтому я думаю, что это не проблема.

Любая помощь будет оценена по достоинству.

Спасибо.

ответ

0

В CakePHP 2.5 следует использовать CakeEmail

Создайте файл /app/Config/email.php с классом EmailConfig. В файле /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('[email protected]', 'Thanks!', 'Thank you for the transaction!', array('from' => '[email protected]')); 

или

$Email = new CakeEmail(); 
$Email->template('email_template', 'email_layout') 
    ->emailFormat('html') 
    ->to('[email protected]') 
    ->from('[email protected]') 
    ->viewVars(array('id' => $txnId)) 
    ->send(); 

шаблон электронной почты переходит к /app/View/Emails/html/email_template.ctp

макетов электронной почты идет в /app/View/Layouts/Emails/html/email_layout.ctp