Integrate Your Autoresponder With cURL

by Carl

If you have a membership system, blog or e-learning application, you most likely want to put your new sign-ups into some type of autoresponder system at the same time.  However, you really don’t want to make them sign up twice – once for your application, and once for the autoresponder.  Wouldn’t it be nice if you could auto-subscribe your new members to your mailing list application automatically?

If you use Aweber, or a similar service, you can just have your membership system shoot an email to yourListName@aweber.com – your recipient will automatically receive an opt-in verification message from Aweber.  Many 3rd party services are integrated with Aweber, like E-Junkie – you can configure the E-Junkie cart to prompt Aweber to send a verification message automatically.

What if you run your own autoresponder script?  What if your autoresponder script does not support subscribe by email? Is there a way to easily integrate an autoresponder script with another type of system?  Thankfully, the answer is ‘Yes’ – with a little PHP scripting.

PHP supports a very cool little extension called cURL – this library of software magic allows you to automate lots of things over the Internet – including the filling out of autoresponder subscription forms.  To get this to work, you need PHP with cURL support (most any unix/linux webhost).  If you don’t know if your host has this, just ask.

Step 1 : get the html source of your autoresponder subscription form – make sure it’s the form for the correct mailing list – as most scripts put some kind of long ‘form id’ within the sign-up form.  This code tells the autoresponder which list the form is requesting.  Note: if you are using a service like Aweber Get the HTML version of your form, not the javascript version.  Open the html form in your notepad application.

You will need to document following from your autoresponder html submission form:

1.  The post action url (note that for some autoresponders, the subscribe script may have a querystring variable appended to the script, to help identify the correct mailing list or account-I’ve included one in this example- not all scripts will require a querystring):

<form method="post" action=http://scriptdomain.com/path/subscribe.php?listID=343 >

2. The Name and Email name attributes:

<input  value="" name="FirstName" type="text" size="30" >

<input  value="" name="Email" type="text" size="30" >

Your code will look a bit different, but all these forms have a name and email input field.  You want to note the ‘name’ attributes – you’ll need them for the script.

3. Now identify any ‘hidden’ input fields in your form and note the ‘name’ attribute.

<input type="hidden" name="FormCode"

value="9a2bba0636de2430693f445480875730">

4.  Next, document all of the form fields for your script:

url: http://scriptdomain.com/path/subscribe.php?listID=343

Form Fields:
Email
FirstName
FormCode

5.  Ok – now let’s code the integration (I’m assuming PHP here):

<?php
 

//first, find the variables in your sign-up script that contain the user's first

// name and email

//again, your code will look different - //just find the variables for first name and email

//your script may use a simple $_POST function as in the example below for

//$firstname  - Or your script may have a more secure and modular way to 

//define the variable, like the example below for $email ...
 
 
$firstName=$_POST['firstName'];
 
$email=AWLRequest::post('email',45);
 
// ok, now somewhere after your script processes the sign -up, put this code:
 
//NOTE: always use //MOD comments around your changes!
 
//DSP MOD:send message to autoresponder

 

// create a new curl resource
$ch = curl_init();
 

// set URL and other appropriate options - use the url for your subscribe script

 
curl_setopt($ch, CURLOPT_URL, http://scriptdomain.com/path/subscribe.php?listID=343);
 

// Do a POST - this is an array - the HTML field names from your submit form// are the 'keys'

 
$data = array('FirstName' => $firstName, 'Email' => $email,'FormCode'=>'9a2bba0636de2430693f445480875730');
 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 
// execute cURL command:
$exec=curl_exec($ch);
 
            //END DSP MOD

And that’s all you do!  Each time your form processing script executes, the user’s name and email are sent to your autoresponder script for processing.

To test this script, create a stand-alone version of the cURL code only,  with hard-coded values for the firstname an an email address like this:

<?php

$email = 'me@mydomain.com';
$firstName = 'My name';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://scriptdomain.com/path/subscribe.php?listID=343");
// get the vars

// Do a POST
$data = array('Fields[1]' => $firstName, 'Email' => $email,
        'FormCode'=>'9a2bba0636de2430693f445480875730',
                      'Format'=>'1','SelectLists[1]'=>'YES');//note - splitting lines in php code is ok - php looks for the ending semicolon to //tell the end of a line of code

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// grab URL, and print
$exec=curl_exec($ch);
?>

Now save this script with any name you want, upload to your server and load it into your web browser.  If all is working, you’ll get an email from your autoresponder script.

Troubleshooting tips:

Make sure you have the correct form field names from the sign up form

Make sure your path to the subscribe.php or whatever it’s called for your autoresponder system is correct.

Be sure that your web host allows cURL (almost all do).

The #1 coding error for PHP beginners – forgetting the semicolon at the end of each line!

Best Regards,

Carl

Post to Twitter

{ 3 comments… read them below or add one }

managedforexaccounts December 11, 2009 at 9:19 pm

a very useful post, ill try this code and see if it works.
cheers!

Korab January 22, 2010 at 9:34 am

I am currently been working on my WP blog. I’ll check if this one work with me. Thanks for sharing.

Blaster March 4, 2010 at 2:02 am

Thanks its really works!

Leave a Comment

BLOG COMMENT POLICY:

This is a dofollow blog - so you WILL get link juice from putting a comment here. To make things better for everyone, I've installed KeywordLuv and CommentLuv. However, you have to post your comment in the correct manner to get it approved. In the 'Name' field - you MUST to put it in this format: YourName@YourKeywords. Only then will your comment get approved.

Secondly, your comment HAS to be relevant to the post, and add to the content and discussion. I delete comments that are obviously spam, and ban the user's IP as well. Ugly, ugly world we live in. But if you have a relevant comment and want a link, I'm ready to oblige.

CommentLuv Enabled

This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage.

Previous post: A Split Testing Script Improves Conversions

Next post: A Simple Affiliate Cookie Stuffer Plugin For Wordpress