【发布时间】:2016-02-11 08:25:16
【问题描述】:
我正在使用以下代码使用 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得到这个代码
【问题讨论】:
-
如果您的代码在防火墙后运行,请检查您是否可以使用端口 443 远程登录主机
-
不知道这是否相关,但在 apidocs.mailchimp.com/sts 之上,它说,“MailChimp API v3.0 现已上线!以前的版本已被弃用,因此所有 API 用户都应该开始过渡到 v3.0。”
-
尝试将
url更改为:https://<dc>.api.mailchimp.com/3.0/和<dc>位于apikey 的末尾(- 后面),例如us6 -
更改 url 后我得到 "type":"developer.mailchimp.com/documentation/mailchimp/guides/… Not Found","status":404,"detail":"找不到资源 'Sendemail_Collection'。","instance ":""
-
您可能需要坚持使用 2.0 api 版本,因为目前并非所有功能都在 v3 中。但在 v2 中,一般 url 是
https://<dc>.api.mailchimp.com/2.0/