简体   繁体   中英

Mailchimp send email not working

I am using the below code to send email with mailchimp api key.but it returns curl error 6 " Could not resolve host: us1.sts.mailchimp.com "

$to_emails = array('you@example.com', 'your_mom@example.com');
$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'=>'verifed@example.com',
    '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";

I got this code from https://apidocs.mailchimp.com/sts/1.0/sendemail.func.php

        Change $url to API specific endpoint
        Official documentation MailChimp v3.0
            As seen above, the generic format for the API endpoint i
                https://<dc>.api.mailchimp.com/3.0/

            Where <dc> should be replaced with the portion after the dash in your API Key. e.g. "us1", "us2", "uk1", etc.
            A solid example - say your API Key is myapikey-us2. You are in us2, so your API Endpoint would be:
                https://us2.api.mailchimp.com/3.0/ 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM