Wordpress Contact Form 7 manually add Aweber subscribers in PHP

Add this function to the Contact Form 7 functions.php file in the /wp-content/plugins/contact-form-7/includes folder.

Works with Contact Form 7 v3.9 upwards

Change the details to your Aweber list name, meta ad tracking, form id etc. The redirect and redirect_onlist doesn't actually go the page specified (can be removed if you like)

Note: the user still has to confirm the subscription via email to be successfully added to the Aweber list

function process_aweber($cf7) {

$submission = WPCF7_Submission::get_instance();

if ( $submission ) {

$name = $_POST['your-name'];
$email = $_POST['your-email'];

$str=
'meta_web_form_id='.urlencode('000000000').
'&meta_split_id='.urlencode('').
'&meta_redirect_onlist='.urlencode('http://www.yourdomain.co.za').
'&meta_tooltip='.urlencode('').
'&listname='.urlencode('yourListIDhere').
'&redirect='.urlencode('http://www.yourdomain.co.za').
'&meta_adtracking='.urlencode('Enquiry_Form').
'&meta_message='.urlencode('1').
'&name='.urlencode($name).
'&email='.urlencode($email)
;
$url = 'http://www.aweber.com/scripts/addlead.pl';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Expect:'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$response = curl_exec($ch);
curl_close($ch);

}
}
add_action('wpcf7_before_send_mail', 'process_aweber');




Comments

Popular posts from this blog

How To: Get Cell C HSDPA USB dongle to work in Ubuntu

How to Display Custom Wordpress Header with Google Analytics Site Tage and Adwords Site Tag

Enqueue Stylesheet or Javascript on just one Wordpress Page or Post