250 International Parkway Suite 134 Heathrow, FL 32746

Call Us Today  1 - 800-314-8932

PayPal Subscription and Payment Plan Buttons Integrated with Aweber

If you have a subscription service, or payment plan button on your website and you’ve tried to integrate it with Aweber so that the payee is automatically subscribed to your Aweber Newsletter, then you may have come across the problem that Aweber only supports a Buy It Now button or link.

Using PHP (and lots of other languages), you can perform a PayPal -> YourSite -> Aweber transaction that does the same thing for a Subscription or Payment Plan button. You can’t do an automatic PayPal -> Aweber transaction, but this the best work around we’ve come up with.

Quick Summary for the impatient: Copy the code in the text box below, and customize the two options at the top of the script which are notated in the code.

The first thing necessary is to create a page on your website with the following code. This code will have two options we need to customize before it will work, but we need the url of your thank you page before we get into the paypal setup, so create that page first.


// These two items are the only two you need to edit.

// 1. add your key here

$auth_token = "RtWe0qNpNLiZlsdkdiseESasdr3vqpqlimqNzvfSPqHFhgKUc0bVhwKdgwNy";

// 2. add your aweber list name to the beginning of this email address

$aweber_email_list = "list-name@aweber.com";

// read the post from PayPal system and add 'cmd'

$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

$req .= "&tx=$tx_token&at=$auth_token";
// post back to PayPal system to validate

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";

$header .= "Content-Type: application/x-www-form-urlencoded\r\n";

$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

// If possible, securely post back to paypal using HTTPS

// Your PHP server will need to be SSL enabled

// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {


} else {

fputs ($fp, $header . $req);

// read the body data

$res = '';

$headerdone = false;

while (!feof($fp)) {

$line = fgets ($fp, 1024);

if (strcmp($line, "\r\n") == 0) {

// read the header

$headerdone = true;


else if ($headerdone)


// header has been read. now read the contents

$res .= $line;


// parse the data

$lines = explode("\n", $res);

$keyarray = array();

if (strcmp ($lines[0], "SUCCESS") == 0) {

for ($i=1; $i<count($lines);$i++){

list($key,$val) = explode("=", $lines[$i]);

$keyarray[urldecode($key)] = urldecode($val);


// check the payment_status is Completed

// check that txn_id has not been previously processed

// check that receiver_email is your Primary PayPal email

// check that payment_amount/payment_currency are correct

// process payment

$firstname = $keyarray['first_name'];

$lastname = $keyarray['last_name'];

$email = $keyarray['payer_email'];

$itemname = $keyarray['item_name'];

$amount = $keyarray['payment_gross'];
$headers = 'From: "'.$firstname.' '.$lastname.'" <'.$email.'>' . "\r\n" .

'Reply-To: "'.$firstname.' '.$lastname.'" <'.$email.'>' . "\r\n" .

'X-Mailer: PHP/' . phpversion();
mail($aweber_email_list, '', '', $headers);
echo ("<p><h3>Thank you for your purchase!</h3>Please check your email in 5-10 minutes to confirm your subscription.</p>");
echo ("<b>Payment Details</b><br>\n");

echo ("<li>Name: ".$firstname." ".$lastname."</li>\n");

echo ("<li>Email: ".$email."</li>\n");

echo ("<li>Item: ".$itemname."</li>\n");

echo ("<li>Amount: $".$amount."</li>\n");

echo ("");


else if (strcmp ($lines[0], "FAIL") == 0) {

// log for manual investigation

fclose ($fp);
Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br />

You may log into your account at <a xhref='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br />

####END CODE#####
Now that you have a new page, and you’ve got the url to that page, now go to PayPal and setup your Subscription Button. After filling in the necessary items, click the “Add More Options��? button instead of the “Create Button Now��?. On the more options page choose paste the url to the page you just created into Successful Payment URL input box. Then next to the text “Payment Data Transfer��? click the Edit button. On this page turn “Auto Return��? to “On��?. Paste your url again in the input box below that. Now scroll down turn “Payment Data Transfer��? to “On��? and now copy the “Identity Token��? and put it into the page you created on your website. Set the rest of your options as needed, click “Save��?, then on the next page “Create Button Now��?.

Now you should of course copy and paste your button code into your site. Then there is just one more option to setup. Go to your Aweber account get your list name, and put that into the script on your site as the email address “list-name@aweber.com��?. You should be all set now, with your website now sending an email to Aweber about the new subscription.

Note: If you’re on a shared hosting plan you may experience difficulties with the very simple mail script because your host may require that you send emails from or to a domain within your account. If thats the case, adding a BCC or CC to the email script so that a copy goes to your domain should work.

Download aweber - paypal pap here.