首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何通过MailChimp 3.0API发送电子邮件?

如何通过MailChimp 3.0API发送电子邮件?
EN

Stack Overflow用户
提问于 2015-07-30 16:23:51
回答 2查看 34.6K关注 0票数 12

我试图在php中通过mailchimp api 3.0版发送电子邮件,但我没有运气。这是我的代码:

代码语言:javascript
复制
$postString = '{
        "message": {
            "html": "this is the emails html content",
            "text": "this is the emails text content",
            "subject": "this is the subject",
            "from_email": "xxx@dyyy.sk",
            "from_name": "John",
            "to_email": "aaa.bbb@gmail.com",
            "to_name": "Anton",
            "track_opens": false,
            "track_clicks": false
        }}';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->api_endpoint);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
        curl_setopt($ch, CURLOPT_USERPWD, 'drewm:'.$this->api_key);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.api+json', 'Content-Type: application/vnd.api+json'));
        curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

        $result = curl_exec($ch);

        echo $result;

我做错了什么?

EN

回答 2

Stack Overflow用户

发布于 2018-07-30 02:05:19

您不能像使用v1时那样,从v3接口随机发送电子邮件。现在,您只能按照LamaDelRay的说明,在MailChimp中发送之前创建的活动。

票数 5
EN

Stack Overflow用户

发布于 2016-03-14 15:46:53

代码语言:javascript
复制
<?php
//require_once('mailchimpint/mcapi/inc/MCAPI.class.php');
$apikey = 'Your api';

$to_emails = array('to email 1', 'toemail 2');
$to_names = array('Name 1', 'Name 2');

$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'=>'',
    '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://us5.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);
 var_dump($result);
$data = json_decode($result);

echo "Status = ".$data->status."\n";
 ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31718660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档