latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Custom API Notifications

Home Forums Community Forum Custom API Notifications

This topic contains 9 replies, has 4 voices. Last updated by  Cristián Lávaque 4 years, 1 month ago.

Topic Author Topic
Posted: Wednesday Nov 28th, 2012 at 3:39 pm #32803

Hello,

I’m wondering if you can help me with a problem that I’m not sure how to resolve.

I’m wanting to be able to set up (through API notifications), a custom email (using wpmail) that is sent out upon a new sign-up on the website. I would like to be able to include all the information (username, password, membership level, recurring amount….and maybe some others) all in one email.

I’ve watched the tutorial videos for API notifications and I get the concept but I think my code isn’t right because I’m not getting anything.

Here is what i have as my Notifier url:

http://insidemusicmedia.com/wp-content/themes/colliano/signup-notifier.php?secretKey=imm3467294710&member=%%item_name%%&fname=%%full_name%%&email=%%payer_email%%&subid=%%subscr_id%%&amount=%%recurring%%

And here is what is in my “signup-notifer.php” file:

<?php

// IMM

if ($_GET["secretKey"] === "imm3467294710")
    {
        $to = 'cdelcolliano@earthlink.net' ;
        $headers[] = 'From: Inside Music Media <jdelcolliano@earthlink.net>';
        $headers[] = 'Cc: paul@wordfresh.com';
        $subject = 'New Member Notification';
        if ($_GET['amount'] === '9.99')
        {
            $message = '<h2>New Monthly Member</h2><ul><li>' . $_GET['member'] . '</li><li>Name:' . $_GET['fname'] . '</li><li>Email:' . $_GET['email'] . '</li><li>Name:' . $_GET['subid'] . '</li></ul>'; 
        } else {
            $message = '<h2>New Annual Member</h2><ul><li>' . $_GET['member'] . '</li><li>Name:' . $_GET['fname'] . '</li><li>Email:' . $_GET['email'] . '</li><li>Name:' . $_GET['subid'] . '</li></ul>';   
        }
           
            wp_mail( $to, $subject, $message, $headers );
        
    }
?>

What am I doing wrong here?

I really appreciate your help. You guys have been huge help in the past. It doesn’t go unnoticed.

Thank you!

List Of Topic Replies

Viewing 9 replies - 1 through 9 (of 9 total)
Author Replies
Author Replies
Posted: Wednesday Nov 28th, 2012 at 4:55 pm #32828
Raam Dev
Username: Raam
Staff Member

Hi Cheryl,

There are a large number of possible reasons the code might not be working. There are no obvious bugs that stand out to me, but it could be that wp_mail() isn’t sending the email for some reason.

To debug this issue, I recommend that you start by ruling things out. Instead of sending an email with all that data, try writing some code that just writes the data to a log file. Then check if the log file contains the data you’re expecting after a successful signup.

Next, you can try creating a PHP file that sends an email using pre-filled data to see if you can actually get it to send the email.

Actually, as I was writing that previous sentence, I realized that you’re using the wp_mail() function, which is a WordPress function. However, you’re not loading the WordPress framework in your signup-notifer.php file. If you don’t load WordPress, you won’t have access to the wp_mail() function. So, instead of using wp_mail() you might try using the PHP mail() function.

Finally, there are a few helpful plugins mentioned in Troubleshooting Email Delivery Problems that you may want to install.

Posted: Friday Nov 30th, 2012 at 4:18 pm #33041

Thank you Raam,

So when you say that wordpress framework is not loaded in the php doc, how would one do that?

I have the signup-notifier.php nested in my main wordpress folder.

Any suggestions?

Posted: Friday Nov 30th, 2012 at 5:42 pm #33058
Raam Dev
Username: Raam
Staff Member

Hi Cheryl,

This article should be helpful.

Posted: Wednesday Dec 5th, 2012 at 2:38 pm #33598

That is extremely helpful and exactly what I needed! Thank you Raam!

I just have one more question.

What I’m trying to do is build a notification email that holds almost all of the pertinent information about a new subscription for our administrators. I see that with a Sign up Api notification, you can only pass certain information into the Notification url using replacement codes. For instance, I cannot add in the user’s username and password with the available replacement codes.

Basically, I would like most of the option available already, and I would like to also display Username and Password in this email as well.

Is that what the cv1, cv2 is there for?

Thanks for your help on this.

Posted: Wednesday Dec 5th, 2012 at 3:21 pm #33609
Bruce
Username: Bruce
Staff Member

Hi Cheryl,

s2Member currently does not support all of the information that you need, as it is meant to be a way to connect to Affiliate programs and other sotware outside of WordPress that would have no use for this information.

Therefore, instead of using API Notifications, I recommend just using the core WordPress functionality to get the user’s data, and querying PayPal for subscription info.

Instead of using s2Member’s API Notifications it may be easier to just hook into WordPress’s user_register hook. This hook should give you all the info you need to send your email. Make sure to use a lower priority than s2Member, however. s2Member uses the default 10 priority, so using something like this should work, in a Must-Use Plugin within your /wp-content/mu-plugins/ directory (create it if you don’t have it):

<?php
add_action('user_register', 's2hack_user_register_email', 20, 1);

function s2hack_user_register_email($id) {
	$user = new WP_User($id);
	
	$subscr_id = get_user_option('s2member_subscr_id', $id); // User's current PP subscription ID.
		$paypal = array ('METHOD' => 'GetRecurringPaymentsProfileDetails', 'PROFILEID' => $subscr_id); // API call configuration.
		
	if (($paypal = c_ws_plugin__s2member_paypal_utilities::paypal_api_response ($paypal)) && !$paypal['__error'])
				$type = $paypal['BILLINGPERIOD']; // The billing period for the 
	
	$to =  $user->user_email; // 'cdelcolliano@earthlink.net' ;
        $headers[] = 'From: Inside Music Media <jdelcolliano@earthlink.net>';
        $headers[] = 'Cc: paul@wordfresh.com';
        $subject = 'New Member Notification';

	### USER DETAILS ###
	$first_name = $user->first_name;
	$last_name = $user->last_name;
	$email = $user->user_email;
	### USER DETAILS ###

	if($type === 'Month') {
		// This is a monthly subscriber.
	}
	elseif($type === 'Year') {
		// This is a yearly subsriber.
	}
}

The user_register code gives you the user’s ID, which allows you to then get all of their info by creating a new WP_User(). Find info on this at:

http://codex.wordpress.org/Class_Reference/WP_User

This code also performs a query to PayPal to find info on their billing cycle. Find info on the data recieved here:

https://www.x.com/developers/paypal/documentation-tools/api/getrecurringpaymentsprofiledetails-api-operation-nvp

This code would only work for users that are creating an account. So if you have free registration enabled, or if you have the ability for users to upgrade their accounts, this would need to be tweaked a bit.
Posted: Thursday Dec 6th, 2012 at 9:19 pm #33832

Thank you so much for the in-depth answer, I will give it shot.
I understand all that your talking about except the “MU-Plugins” part. So I would create a folder called MU-Plugins, and then what?

And how would I reference this code or would it automatically be called upon a new registration to the site?

Posted: Friday Dec 7th, 2012 at 8:04 am #33875

You’d put that code in a file, e.g. s2hacks.php, and put the file in the must-use plugins directory, i.e. /wp-content/mu-plugins/ (create it if it’s not there yet). Must-use plugins are loaded automatically by WordPress. http://codex.wordpress.org/Must_Use_Plugins

Posted: Friday Dec 7th, 2012 at 2:32 pm #33912

Ok,

Thank you very much guys!

You guys rock. :)

Posted: Friday Dec 7th, 2012 at 6:10 pm #33939

Thanks! Glad to help. :)

Viewing 9 replies - 1 through 9 (of 9 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.