将Mailchimp链接到注册框

时间:2015-10-06 00:25:56

标签: php email mailchimp

我将电子邮件注册和邮政编码(英国邮政编码英语)输入框(请参阅下面的html代码)链接到现有的Mailchimp电子邮件列表。我从下面的代码中取出了$ apiKey,$ listId和$ submit_url标识符。我已经能够成功地将Mailchimp列表链接到电子邮件输入(以便在Mailchimp列表中输入时填充电子邮件地址,但我无法弄清楚如何在邮箱列表中自动更新邮件代码他们是输入)。

我对php相对较新,对任何帮助都会非常感激。

<div class="subscribe">
            <form method="post" action="bokacsubscribe.php" role="form"> 
            <input type="email" placeholder="Enter your e-mail address..." class="subscribe-input" name="email" style="margin-bottom: 10px;">
                <form method="post" action="bokacsubscribe.php" role="form"> 
            <input type="email" placeholder="Enter your postcode" class="subscribe-input" name="postcode" style="margin-bottom: 10px;">
            <button type="submit" class="btn btn-subscribe success" style="border-radius:120px;background-color:rgb(241,174,200);border:1px solid rgb(241,174,200)"><b>Send</b></button>
     <input type="hidden" name="referr" id="referr"/>          
          </form>
         </div>
         </div>



<?php
// Credits: https://gist.github.com/mfkp/1488819

session_cache_limiter('nocache');

$apiKey    = ''; - // How get your Mailchimp API KEY - http://kb.mailchimp.com/article/where-can-i-find-my-api-key
$listId    = ''; - // How to get your Mailchimp LIST ID - http://kb.mailchimp.com/article/how-can-i-find-my-list-id
$submit_url    = ""; - // Replace us2 with your actual datacenter

$double_optin = false;
$send_welcome = false;
$email_type = 'html';
$email = $_POST['email'];
$merge_vars = array( 'YNAME' => $_POST['yname'] );

$data = array(
'email_address' => $email,
'apikey' => $apiKey,
'id' => $listId,
'double_optin' => $double_optin,
'send_welcome' => $send_welcome,
'merge_vars' => $merge_vars,
'email_type' => $email_type
);

$payload = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submit_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode($payload));

$result = curl_exec($ch);
curl_close ($ch);

$data = json_decode($result);

if ($data->error) {
// do whatever you do on failure here
} else {
// do whatever you do on success here
$arrResult = array ('response'=>'success');
}

0 个答案:

没有答案