title: How do I implement a mailchimp API in a email signup form?
body: <p>Here is a snippet of html that comes from a website template that has a MailChimp API form.</p>
  
  <pre><code>&lt;div class="row"&gt;
    &lt;div class="col-md-6 col-sm-12 col-md-offset-3 subscribe"&gt;
      &lt;form class="form-horizontal" role="form" action="subscribe.php" id="subscribeForm" method="POST"&gt;
        &lt;div class="form-group"&gt;
          &lt;div class="col-md-7 col-sm-6 col-sm-offset-1 col-md-offset-0"&gt;
            &lt;input class="form-control input-lg" name="email" type="email" id="address" placeholder="Enter your email" data-validate="validate(required, email)" required="required"&gt;
          &lt;/div&gt;
          &lt;div class="col-md-5 col-sm-4"&gt;
            &lt;button type="submit" class="btn btn-success btn-lg"&gt;SIGN UP TO BE NOTIFIED&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/form&gt;
      &lt;span id="result" class="alertMsg"&gt;&lt;/span&gt; &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the email submission form for the website template that I'm currently using. This form directly submits an email to my account; my question is: how can I turn the following form into a mailchimp API form? I mainly want to use it because it's correctly formatted already for the website im making - aka it works with the css I have and it's properly sized, etc.</p>
  
  <pre><code>&lt;div class="newsletter"&gt;
   &lt;form action="subscribe.php" method="post" id="newsletter-form"&gt;
    &lt;p class="form-field"&gt;
     &lt;label for="newsletter_email" class="visually-hidden"&gt;Your email address&lt;/label&gt;
     &lt;i class="icon ion-paper-airplane" aria-hidden="true"&gt;&lt;/i&gt;
     &lt;input type="text" name="newsletter_email" id="newsletter_email" value="" placeholder="Your email address" /&gt;
    &lt;/p&gt;
    &lt;p class="form-submit"&gt;
     &lt;input type="submit" name="newsletter_submit" id="newsletter_submit" value="Get Notified" /&gt;
    &lt;/p&gt;
   &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>thanks for helping! sorry for the long post. I'm not sure what the etiquette on stackoverflow is, so if i'm asking a crappy question, let me know.</p>
  
  <p>EDIT:</p>
  
  <p><a href="http://i.stack.imgur.com/tCZ7S.png" rel="nofollow">http://i.stack.imgur.com/tCZ7S.png</a></p>
  
  <p>this is a screenshot of the two forms on my current template. top one is the original form, that sends subscriber emails to my email directly, and bottom is the mailchimp form. in addition to not being formatted properly, the mailchimp form also sends me to a blank page after i enter my email, instead of just returning a simple thank you message on the page as it should (as in:</p>
  
  <pre><code>} else {
      echo "Thanks! We'll keep you updated on the conference :)";
  }
  </code></pre>
  
  <p>)</p>
  
  <p>Here is the subscribe.php from the mailchimp template:</p>
  
  <pre><code>&lt;?php
  $apiKey = '';
  $listId = '';
  $double_optin=true;
  $send_welcome=true;
  $email_type = 'html';
  $email = $_POST['email'];
  //replace us2 with your actual datacenter
  $submit_url = "http://us1.api.mailchimp.com/1.3/?method=listSubscribe";
  $data = array(
      'email_address'=&gt;$email,
      'apikey'=&gt;$apiKey,
      'id' =&gt; $listId,
      'double_optin' =&gt; $double_optin,
      'send_welcome' =&gt; $send_welcome,
      'email_type' =&gt; $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-&gt;error){
      echo $data-&gt;error;
  } else {
      echo "Thanks! We'll keep you updated on the conference :)";
  }
  ?&gt;
  </code></pre>