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".

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

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行