Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sending email using mail chimp api

Tags:

php

api

mailchimp

i am trying to send email using mail chimp api but the following error occours

{"aws_type":null,"aws_code":null,"http_code":500,"message":"Invalid Mailchimp API Key: <snip>-us5 . You are accessing the wrong datacenter - your client library may not properly support our datacenter mapping scheme."}

i checked my mailchimp api key and its correct.If any one know please reply below is my code

    $apikey = 'api_key';

$to_emails = array('[email protected]');
$to_names = array('You', 'Your Mom');

$message = array(
    'html'=>'Yo, this is the <b>html</b> portion',
    'text'=>'Yo, this is the *text* portion',
    'subject'=>'This is the subject',
    'from_name'=>'Me!',
    'from_email'=>'[email protected]',
    'to_email'=>$to_emails,
    'to_name'=>$to_names
);

$tags = array('WelcomeEmail');

$params = array(
    'apikey'=>$apikey,
    'message'=>$message,
    'track_opens'=>true,
    'track_clicks'=>false,
    'tags'=>$tags
);

$url = "http://us1.sts.mailchimp.com/1.0/SendEmail";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);
echo $result;
curl_close ($ch);

$data = json_decode($result);
echo "Status = ".$data->status."\n";
like image 682
rohit Avatar asked Nov 03 '22 18:11

rohit


1 Answers

Without doing more research, I'd try changing $url to http://us5.sts.mailchimp.com/1.0/SendEmail since your API key ends in -us5 and it's complaining that you're hitting the wrong data center.

like image 162
sblom Avatar answered Nov 15 '22 06:11

sblom