我有以下 PHP“订阅”脚本,我正在使用它来允许用户注册我的 MailChimp 列表。
它按预期工作(将我的电子邮件地址添加到我的 MailChimp 列表中),但我在提交时也收到错误消息。
这是我的错误:
Notice: Trying to get property of non-object in
E:\domains\*******\subscribe.php on line 29
第 29 行是:if ($data->error){
这是我的代码:
<?php
$apiKey = '*********************************';
$listId = '*******************';
$double_optin=true;
$send_welcome=false;
$email_type = 'html';
$email = $_POST['email'];
//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 "Thanks. You will receive an email shortly to confirm your subscription.";
}
如果我还提供了我正在使用的 HTML 表单代码和 AJAX,会有帮助吗?
非常感谢您的帮助:-)