我创建了一个插件,用于在使用paypal捐赠后向用户发送电子邮件。但问题是用户没有收到任何电子邮件。请检查下面的代码。我也使用名为" PayPal IPN的插件用于WordPress"获取捐赠信息。
<?php
/*
Plugin Name: PayPal IPN Send Email
Plugin URI: http://www.trustedwebsolution.com/
Description: Hook tester for PayPal IPN for WordPress plugin.
Author: Jhishu Singha
Version: 1.0.0
*/
add_action('paypal_ipn_for_wordpress_payment_status_processed', 'paypal_ipn_for_wordpress_payment_email', 10, 1);
function paypal_ipn_for_wordpress_payment_email($posted) {
// Parse data from IPN $posted array
$dir = plugin_dir_url( __FILE__ );
$item_name = isset($posted['item_name']) ? $posted['item_name'] : '';
$payment_gross = isset($posted['payment_gross']) ? $posted['payment_gross'] : '';
$first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
$last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
$payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : '';
$subscr_date = isset($posted['subscr_date']) ? $posted['subscr_date'] : '';
/**
* At this point you can use the data to generate email notifications,
* update your local database, hit 3rd party web services, or anything
* else you might want to automate based on this type of IPN.
*/
if($item_name == 'ATF Donation') {
$to = $payer_email;
$subject = 'Email from Adaptive Training Foundation';
$message = 'Thanks for donation';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $message, $headers );
} else {
// No email
}
}
?>
我试图解决它几天。但没有运气。在此先感谢您的帮助。
答案 0 :(得分:1)
我认为你应该使用不同的钩子。而不是paypal_ipn_for_wordpress_payment_status_processed
使用paypal_ipn_for_wordpress_payment_status_completed
,看看是否有帮助。
另外,出于测试目的,我会在你声明的else部分给自己添加一封电子邮件,这样如果代码落在那里你就会得到一些东西,你不会认为IPN根本就没有运行过。