我们可以通过localhost使用MailChimp订阅吗?

时间:2015-05-27 09:07:49

标签: php mailchimp subscribe

我是第一次这样做。我想问一下,我可以通过本地服务器使用MailChimp进行订阅,因为我每次都遇到问题。当我订阅时,我没有收到任何邮件。这是代码

<?php
 // change this path if the class file isn't in the same directory!
 include_once 'MailChimp.php';
 $alertclass = 'alert-warning';
 $msg = '';
 $name = '';
 $email = '';
 if (isset($POST['Submit'])) {
 if (empty($_POST['name']) || empty($_POST['email'])) {
 $msg = 'Please enter a name and email address.';
 } else {
 $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
 $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    /*
     * Place here your validation and other code you're using to process your contact form.
    */
 $mc = new \Drewm\MailChimp('xxxxxxxxx-us11');
 $mvars = array('optin_ip'=> $_SERVER['REMOTE_ADDR'], 'FNAME' => $name);
 $result = $mc->call('lists/subscribe', array(
            'id'                => 'f660c6ba5f',
            'email'             => array('email'=>$email),
            'merge_vars'        => $mvars,
            'double_optin'      => true,
            'update_existing'   => false,
            'replace_interests' => false,
            'send_welcome'      => false
        )
 );
 if (!empty($result['euid'])) {
 $msg = 'Thanks, please check your mailbox and confirm the subscription.';
        $alertclass = 'alert-success';
    } else {
        if (isset($result['status'])) {
            switch ($result['code']) {
                case 214:
                $msg = 'You\'re already a member of this list.';
                break;
                // check the MailChimp API if you like to add more options
                default:
                $msg = 'An unknown error occurred.';
                $alertclass = 'alert-error';
                break;
            }
        }$msg="asdasdad";

     }
  }
 }
?>

我对此很新。

html代码

  <form class="form-horizontal"action="contactform-mailchimp.php" method="post">
  <?php
  //if ($msg != '') 
  echo '
  <div class="alert '.$alertclass.'" role="alert">'.$msg.'</div>';
  ?>
   <div class="form-group">
    <label for="inputName" class="col-sm-2 control-label">First name</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" name="name" id="inputName">
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-10">
      <input type="email" class="form-control" name="email" id="inputEmail">
    </div>
  </div>
  <div class="form-group">
    <label for="inputMessage" class="col-sm-2 control-label">Message</label>
    <div class="col-sm-10">
        <textarea class="form-control" rows="3" name="message" id="inputMessage"></textarea>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <div class="checkbox">
        <label>
          <input type="checkbox" name="newsletter"> Subscribe to newsletter
        </label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" name="Submit" class="btn btn-default">Submit</button>
    </div>
  </div>
</form>

0 个答案:

没有答案