1

我正在尝试将表单中的 $POST_[values] 推送到我的 Mailchimp 联系人列表中,但我可以推送的唯一两个值是“电子邮件”和“状态”(即“订阅”)。

我阅读了所有文档,但无法使用提供的合并字段。

HTML


<div class="input-box">
                    <span>First Name</span>
                    <input type="text" name="FNAME" value="FNAME" tabindex="1">
                </div>
                <div class="input-box">
                    <span>Last Name</span>
                    <input type="text" name="LNAME" value="LNAME" tabindex="2">
                </div>
                <div class="input-box">
                    <span>Email*</span>
                    <input type="email" name="email2" tabindex="3" required>
                </div>
                <div class="input-box">
                    <span>Company*</span>
                    <input type="text" tabindex="4" name="MMERGE9" value="MMERGE9" required>
                </div>
                <input id="submit-download" type="submit" name="submit2" tabindex="5" disabled></input>

PHP


include('./mailchimp/MailChimp.php'); 
$MailChimp = new MailChimp('XXXX');
$list_id = 'XXX';
$email = $_POST['email2'];
$MERGE9 = $_POST['MMERGE9'];
$result = $MailChimp->post("lists/$list_id/members", [
                'email_address' => $email,
                'status'        => 'subscribed',
                'MERGE9'        => $MERGE9,

我尝试了 Mailchimp 提供的所有变体:MERGE9、MMERGE9、|MERGE9|

我使用这个库:https ://github.com/drewm/mailchimp-api

我还尝试使用 curl 命令列出合并字段,但无法正常工作:

https://mailchimp.com/developer/api/marketing/list-merges/

4

1 回答 1

0

注意:这个问题的重点是使用自定义 HTML 表单使用 MC API 将新成员发布到 MailChimp 列表;与验证、安全、垃圾邮件/reCaptcha 和其他重要考虑相关的代码已被省略。我不建议在生产中单独使用此代码。

原始问题:当使用他们的 API [使用 post("lists/$list_id/members")] 向 MC 'list_id' 发布新的 'member' 时,只存储两个字段,'status' 和 'email_address',忽略我希望存储的所有合并字段。

解决方案:'merge_fields' 必须使用 MC API作为数组提交。

为了解决我的问题,我发现使用 GET 使用 curl 直接尝试 API 很有用,因为 drawm 的 mailchimp-api 库很棒,但它隐藏了一些内部工作。

PHP

<?php
include './../mailchimp/MailChimp.php'; // update this \path\to MailChimp.php from drewm mailchimp library (https://github.com/drewm/mailchimp-api);
use \DrewM\MailChimp\MailChimp; // do not change/edit this line;
if(isset($_POST['submit'])) { //edit as needed the name of the submit field in your form;
    $MailChimp = new MailChimp($key); //update $key with your MailChimp API key; should look like 3856ojd298g5q82c2213453a98172346-xx22; can be found under >>Top Right Corner dropdown (displaying your name)>>Account>>Extras>>API Keys>>Create a key [keep this key private as gives partial API access to your account]
    $email = $_POST['email']; // update field name as needed;
    $fname = $_POST['FNAME']; // update field name as needed;
    $lname = $_POST['LNAME']; // update field name as needed;
    $company = $_POST['COMPANY']; // update field name as needed;
    $result = $MailChimp->post("lists/$list_id/members", [      // update $list_id with your list_id; should look like this 'js83js93jm'; can be found under MailChimp.com>>Audience>>Audience Dashboard>>Manage Audience dropdown>>Settings>>Audience name and defaults>>Audience ID
                'email_address' => $email, // this field is a MC API default, don't edit;
                'merge_fields' => [
                    'FNAME' => $fname,
                    'LNAME' => $lname,
                    'MMERGE9' => $company,
                    ],
                'status'        => 'subscribed', // this field is a MC API default, don't edit, although you could possibly remove it if you don't want to add the subscribed status at this point (verify in the docs);
                
            ]);
?>          
于 2020-09-01T22:55:09.920 回答