【问题标题】:Mailchimp send email not workingMailchimp 发送电子邮件不起作用
【发布时间】: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://&lt;dc&gt;.api.mailchimp.com/3.0/&lt;dc&gt; 位于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://&lt;dc&gt;.api.mailchimp.com/2.0/

标签: php email mailchimp


【解决方案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/ 

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 2012-08-13
    • 2011-07-14
    • 2012-08-01
    • 2018-10-30
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多