gpt4 book ai didi

ajax - 使用 API 和 AJAX 发送/包含 'name' 字段到 Mailchimp

转载 作者:行者123 更新时间:2023-12-01 21:39:37 25 4
gpt4 key购买 nike

我需要知道如何将“姓名”字段发送到 Mailchimp,以便它显示用户在 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”

我希望这是您需要的所有信息并且它是有意义的..

非常感谢。

最佳答案

离开此处找到的 Mailchimp listSubscribe 功能文档: http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php

您只需创建一个 merge_vars 数组,该数组将保存与订阅电子邮件关联的任何其他字段。例如:

$merge_vars = array('FNAME'=>'first name', 'LNAME'=>'last name');

然后只需将该数组传递到您的 $data 中即可。

关于ajax - 使用 API 和 AJAX 发送/包含 'name' 字段到 Mailchimp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15682795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com