douxieshang5577 2014-05-28 16:08
浏览 78
已采纳

无法让MailChimp api v2正常工作

I'm trying to implement a newsletter on my website using mailchimp API. I've tried the various suggestions made here, without success (I'm a complete newbie for that kind of things).

The code below should be working, however there's something that I don't understand when the user says "Here is an example using version 2.0 of Mailchimp API together with mailchimp-api (a minimal php abstraction class for dealing with the Mailchimp API)."

When I download the file there's no file called 'MailChimp.class.php". Just one called MailChimp.php. Do I need to rename it or something to get include('MailChimp.class.php'); work? And what about the other files part of mailchimp-api, can I just ignore them? Thanks

<?php

include('MailChimp.class.php');

$MailChimp = new MailChimp('API_KEY');
$result = $MailChimp->call('lists/subscribe', array(
    'id'                => 'LIST_ID',
    'email'             => array( 'email' => $_POST['email'] ),
    'merge_vars'        => array(
        'MERGE2' => $_POST['name'] // MERGE name from list settings
        // there MERGE fields must be set if required in list settings
    ),
    'double_optin'      => false,
    'update_existing'   => true,
    'replace_interests' => false
));

if( $result === false ) {
    // response wasn't even json
}
else if( isset($result->status) && $result->status == 'error' ) {
    // Error info: $result->status, $result->code, $result->name, $result->error
}

?>

HTML:

<div id="email">
        <span>Enter your email to sign up</span>
        <form action="subscribe.php" id="invite" method="POST">
            <input type="text" placeholder="your@email.com" name="email" id="address" data-validate="validate(required, email)"/>
            <button type="submit">&#187;</button>
        </form>
        <span id="result"></span>
    </div>
  • 写回答

1条回答 默认 最新

  • dtc99987 2014-05-28 16:38
    关注

    I accessed the link you mentioned, https://github.com/drewm/mailchimp-api, and in the description, the author shows a piece of code as example.

    $MailChimp = new \Drewm\MailChimp('abc123abc123abc123abc123abc123-us1');
    

    I guess you just need to include the file (don't need to rename it) and then access the library using his namespace "\Drewn".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历