在我的php表单中的checkbox上集成mailchimp

时间:2014-03-26 10:06:24

标签: php checkbox mailchimp

我只是想将一个mailchimp代码集成到我的php表单中,该表单现在发送一封电子邮件,但我有一个复选框,用户可以选中或取消选中是否有新闻和更新

    <div class="checkbox">
       <label>
          <input type="checkbox" id="emailUpdates" name="emailUpdates" value="Yes">    
          Please keep me informed of product updates and news
       </label>
    </div>

PHP

<?php

                            // SUBSCRIBE TO MAILING LIST OPTION - ADD TO MAILCHIMP USING API
                            if ($_POST['emailUpdates'] == 'Yes')
                            {
                                // Include Mailchimp API class
                                require_once('MCAPI.class.php');

                                // Your API Key: http://admin.mailchimp.com/account/api/
                                $api = new MCAPI('feaf699f7a15c1ca27f6903152d4a3f1-us3');

                                // Your List Unique ID: http://admin.mailchimp.com/lists/ (Click "settings")
                                $list_id = "69010111da";

                                // Variables in your form that match up to variables on your subscriber
                                // list. You might have only a single 'name' field, no fields at all, or more
                                // fields that you want to sync up.
                                $merge_vars = array(
                                    'FNAME' => $_POST['first_name'],
                                    'LNAME' => $_POST['last_name']
                                );

                                // SUBSCRIBE TO LIST
                                if ( $api->listSubscribe($list_id, $_POST['email'], $merge_vars) === true ){
                                    $mailchimp_result = 'Success! Check your email to confirm sign up.';
                                } else {
                                    $mailchimp_result = 'Error: ' . $api->errorMessage;
                                }
                            }

                            ?>

在我的本地主机上说

  

注意:未定义的索引:第98行的C:\ xampp \ htdocs \ kinectapi \ contact.php中的emailUpdates

我的代码出了什么问题?有帮助吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

当您的表单submit name="emailUpdates"未被选中时,它返回此类型的数组Undefined index: emailUpdates,表示数组键不是cantain emailUpdates

例如。 $_POST['emailUpdates']