I am trying to integrate Aweber through CURL but it always returns a message "Email Address is Invalid" but if i paste the same url that I am passing to curl in browser address bar it works and adds me to aweber list. Can any one guide me how can i make it work through curl here is my code:
$listname = 'sarnia-basic'; // YOUR LIST NAME
$adtracking = 'sarniabusiness'; // AD TRACKING
$url = 'http://www.aweber.com/scripts/addlead.pl?listname=sarnia-basic&meta_adtracking=sarniabusiness&name=Mohammad Tanveer&email=tanveer_411393@hotmail.com&meta_message=1&redirect=http://www.aweber.com/form/thankyou_vo.html';
$ch1 = curl_init( $url );
$options = array(CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'Mozilla/5.0',
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_FAILONERROR => true,
CURLOPT_AUTOREFERER => true,
);
curl_setopt_array( $ch1, $options );
$mh = curl_multi_init();
curl_multi_add_handle($mh, $ch1);
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);
$html = curl_multi_getcontent($ch1);
curl_multi_remove_handle($mh, $ch1);
curl_multi_close($mh);
You may want to try using urlencode() on your email address before you send it over to aweber...
you should encode url parameters before sending. "@" character in e-mail field should be encoded like "%40". Of course proper way is to use -> http://php.net/manual/en/function.urlencode.php
edit:
$url = 'http://www.aweber.com/scripts/addlead.pl?listname='.urlencode('sarnia-basic').'&meta_adtracking='.urlencode('sarniabusiness').'&name='.urlencode('Mohammad Tanveer').'&email='.urlencode('tanveer_411393@hotmail.com').'&meta_message='.urlencode('1').'&redirect='.urlencode('http://www.aweber.com/form/thankyou_vo.html');
This code works as I use it; however, sending it any other way but directly through a form will result in a) the owner of the email address receiving a confirmation, and b) the subscriber being added from your servers ip address rather than their own which could get you blocked after a while if it violates aweber's TOS. If you need to add the subscriber to the DB or do other processing before submitting, the best way is to do all processing via ajax and once the processing is finished return true so the form will submit.
<?php
$strPost = '';
foreach($_POST as $key => $val)
{
$strPost .= $key . '=' . urlencode(trim($val)) . '&';
}
$strPost = substr($strPost, 0, -1);
$strUrl = 'http://www.aweber.com/scripts/addlead.pl';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
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, $strPost);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$response = curl_exec($ch);
curl_close($ch);
Aweber will block your ip address if you do curl requests to add emails.
They have an API which lets you add subscribers: https://labs.aweber.com/