wordpress联系表单7使用api同步到mailchimp列表

时间:2013-10-16 12:01:42

标签: php wordpress api mailchimp contact-form-7

我正在尝试将联系表单7数据发送到mailchimp列表。到目前为止,这可以很好地遵循本教程http://www.limecanvas.com/a-mailchimp-opt-in-field-for-contact-form-7/

我正在尝试修改php以收集电话号码并将其作为合并标签发布到mailchimp列表中。

function wpcf7_send_to_mailchimp($cfdata) {
     $formtitle = $cfdata->title;
     $formdata = $cfdata->posted_data;
     // Opt-in field checked?
     if ( $formdata['mailchimp-optin'] ) {
     $names = explode(' ',trim($formdata['first-name']));
     $firstName = $names[0];
     $lastName = '';
     if (count($names)>1){
     // more than one word in name field
     $lastName = array_pop($names);
     }
    $send_this_email = $formdata['your-email'];
     $mergeVars = array(
     'FNAME'=>$firstName,
     'LNAME'=>$lastName
     );
     // MCAPI.class.php needs to be in theme/includes folder
    require_once('core/includes/MCAPI.class.php');

     // grab an API Key from http://admin.mailchimp.com/account/api/
     $api = new MCAPI('apikey');
     // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
     // Click the "settings" link for the list - the Unique Id is at the bottom of that page.
     $list_id = 'listid';
     // Send the form content to MailChimp List without double opt-in
     $retval = $api->listSubscribe($list_id, $send_this_email, $mergeVars, 'html', false,true);
     }
    }
    add_action('wpcf7_mail_sent', 'wpcf7_send_to_mailchimp', 1);

我在mailchimp中设置了表单字段,我正在尝试这个:

$telephone = $formdata['you-tell'];

并将merge标记添加到mergetag数组:

'TELL'=>$telephone

我不是一个php人(对jquery更舒服)所以我可能会接近这个错误?

基本上我需要从联系表单7中提取数据并添加到mailchimp mergetag数组。

感谢指针

2 个答案:

答案 0 :(得分:0)

好吧,想出来......真的很简单:

 $tell = $formdata['your-tell'];
 $mergeVars = array(
 'FNAME'=>$firstName,
 'LNAME'=>$lastName,
 'TELL'=>$tell
 );

修改这些行

答案 1 :(得分:0)

MailChimp for WordPress就是这么做的。它将MailChimp API与WordPress HTTP API结合使用,使其不易出错。

以下联系表单7模板会将输入的值提供给您的MailChimp列表。

[text* mc4wp-FNAME]

[text* mc4wp-LNAME]

[tel mc4wp-TELL]

[mc4wp_checkbox "Sign-up to our newsletter."]

希望有所帮助!