Mailchimp发送电子邮件不起作用

时间:2015-11-10 12:46:49

标签: php email mailchimp

我使用以下代码发送带有mailchimp api密钥的电子邮件。但它返回curl错误6" 无法解析主机: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";

我从https://apidocs.mailchimp.com/sts/1.0/sendemail.func.php

获得了此代码

1 个答案:

答案 0 :(得分:1)

        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/