问题描述
我需要知道如何在名称字段发送到Mailchimp,使其显示姓名的用户在Mailchimp页上的名称列下提交的用户。
I need to know how to send the 'name' field to Mailchimp so that it shows the 'name' the user submitted under the name column on the 'subscribers' page in Mailchimp.
的形式是这样的:
<div id="email">
<form action="subscribe.php" id="invite" method="POST">
<input type="text" placeholder="Enter your name.." name="name" id="name" class="name" data-validate="validate(name)"/>
<input type="email" placeholder="and your email address.." name="email" id="MCE-email" class="email" data-validate="validate(required, email)"/>
<p>If you agree with the Terms and Privacy, please press the submit button below.</p>
<div class="clear"><input type="submit" value="Submit" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</form>
<div id="clear"></div>
<div id="result"></div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#invite').ketchup().submit(function() {
if ($(this).ketchup('isValid')) {
var action = $(this).attr('action');
$.ajax({
url: action,
type: 'POST',
data: {
email: $('#MCE-email').val()
},
success: function(data){
$('#result').html(data).css('color', '#a1a1a1', 'padding', '10px 0px 0px 0px');
},
error: function() {
$('#result').html('Sorry, an error occurred.').css('color', 'white');
}
});
}
return false;
});
});
v</script>
的subscribe.php脚本是这样的:
<?php
$apiKey = 'MYAPIKEY';
$listId = 'MYLISTID';
$double_optin=false;
$send_welcome=false;
$email_type = 'html';
$email = $_POST['email'];
$name = $_POST['name'];
//replace us2 with your actual datacenter
$submit_url = "http://us5.api.mailchimp.com/1.3/?method=listSubscribe";
$data = array(
'email_address'=>$email,
'apikey'=>$apiKey,
'id' => $listId,
'double_optin' => $double_optin,
'send_welcome' => $send_welcome,
'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){
echo $data->error;
} else {
echo "Thank you for your email. We'll keep you up to date..";
}
?>
我在Mailchimp形式的名称字段的字段标签是NAME
我希望这是你需要的所有信息,它是有道理的。
I hope this is all the information you need and it makes sense..
感谢各位大大。
推荐答案
去关在这里找到了Mailchimp listSubscribe功能的文档: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
Going off of the Mailchimp listSubscribe function documentation found here:http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php
您只需要创建一个merge_vars阵列将与订阅电子邮件相关的任何其他字段。例如:
You just need to create a merge_vars array that will hold any additional fields associated with the subscribing email. For example:
$merge_vars = array('FNAME'=>'first name', 'LNAME'=>'last name');
然后就是传递数组中的$的数据。
And then just pass that array in your $data.
这篇关于发送/包括“名称”字段Mailchimp使用API和AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!