我正在尝试将电子邮件订阅到PHP中的MailChimp列表。我实际上不是后端开发人员,所以我对此停滞不前:(
我正在使用MailChimp帮助程序PHP库:https : //github.com/drewm/mailchimp-api
我已经搜索了所有互联网,并且只能得到500个内部服务器错误的状态。我已经在生产服务器中。
post("lists/$list_id/members", [ "email_address" => $_POST["txt_mail"], 'merge_fields' => ['FNAME'=>$_POST["txt_name"], 'FPHONE'=>$_POST["txt_phone"], 'FMSG'=>$_POST["txt_message"]], "status" => "subscribed" ]); if ($MailChimp->success()) { echo "Thank you, you have been added to our mailing list.
"; } else { echo $MailChimp->getLastError(); } ?>
小智.. 5
哦,您没有想法,当我遇到这个问题时,我感到多么沮丧。
幸运的是,我发现Misha Rudrastyh的这一方便功能与API 3.0配合得非常好。这是要点:
自从我使用Wordpress以来,我首先将以下代码放入了我的functions.php
文件中(在这里使用您的变量进行编辑)
'', 'FPHONE'=> '', 'FMSG'=> '') ){ $data = array( 'apikey' => $api_key, 'email_address' => $txt_mail, 'status' => $status, 'merge_fields' => $merge_fields ); $mch_api = curl_init(); // initialize cURL connection curl_setopt($mch_api, CURLOPT_URL, 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5(strtolower($data['email_address']))); curl_setopt($mch_api, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode( 'user:'.$api_key ))); curl_setopt($mch_api, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0'); curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true); // return the API response curl_setopt($mch_api, CURLOPT_CUSTOMREQUEST, 'PUT'); // method PUT curl_setopt($mch_api, CURLOPT_TIMEOUT, 10); curl_setopt($mch_api, CURLOPT_POST, true); curl_setopt($mch_api, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($mch_api, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json $result = curl_exec($mch_api); return $result; }
然后,我在表单过程中添加了变量字段:
$FNAME, 'FPHONE' => $FPHONE, 'FMSG' => $FMSG); rudr_mailchimp_subscriber_status($email, $status, $list_id, $api_key, $merge_fields ); ?>
我希望这有帮助。我为此苦了一段时间,直到意识到如何正确地做。
哦,您没有想法,当我遇到这个问题时,我感到多么沮丧。
幸运的是,我发现Misha Rudrastyh的这一方便功能与API 3.0配合得非常好。这是要点:
自从我使用Wordpress以来,我首先将以下代码放入了我的functions.php
文件中(在这里使用您的变量进行编辑)
'', 'FPHONE'=> '', 'FMSG'=> '') ){ $data = array( 'apikey' => $api_key, 'email_address' => $txt_mail, 'status' => $status, 'merge_fields' => $merge_fields ); $mch_api = curl_init(); // initialize cURL connection curl_setopt($mch_api, CURLOPT_URL, 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5(strtolower($data['email_address']))); curl_setopt($mch_api, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode( 'user:'.$api_key ))); curl_setopt($mch_api, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0'); curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true); // return the API response curl_setopt($mch_api, CURLOPT_CUSTOMREQUEST, 'PUT'); // method PUT curl_setopt($mch_api, CURLOPT_TIMEOUT, 10); curl_setopt($mch_api, CURLOPT_POST, true); curl_setopt($mch_api, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($mch_api, CURLOPT_POSTFIELDS, json_encode($data) ); // send data in json $result = curl_exec($mch_api); return $result; }
然后,我在表单过程中添加了变量字段:
$FNAME, 'FPHONE' => $FPHONE, 'FMSG' => $FMSG); rudr_mailchimp_subscriber_status($email, $status, $list_id, $api_key, $merge_fields ); ?>
我希望这有帮助。我为此苦了一段时间,直到意识到如何正确地做。