Guest User

Untitled

a guest
Dec 9th, 2015
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // change this path if the class file isn't in the same directory!
  3. include_once 'php/mailchimp-subscribe/MailChimp.php';
  4.  
  5. $alertclass = 'alert-warning';
  6. $msg = '';
  7. $name = '';
  8. $email = 'xxxx@xxxxx.com';
  9.  
  10. if (isset($POST['Submit'])) {
  11. if (empty($_POST['name']) || empty($_POST['email'])) {
  12. $msg = 'Please enter a name and email address.';
  13. } else {
  14. $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
  15. $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  16. /*
  17. * Place here your validation and other code you're using to process your contact form.
  18. */
  19. $mc = new \Drewm\MailChimp('xxxxxxxxxxxxxxxxxxx');
  20. $mvars = array('optin_ip'=> $_SERVER['REMOTE_ADDR'], 'FNAME' => $name 'MERGE4');
  21. $result = $mc->call('lists/subscribe', array(
  22. 'id' => 'xxxxxxxxx',
  23. 'email' => array('email'=>$email),
  24. 'merge_vars' => $mvars,
  25. 'double_optin' => true,
  26. 'update_existing' => false,
  27. 'replace_interests' => false,
  28. 'send_welcome' => false
  29. )
  30. );
  31. if (!empty($result['euid'])) {
  32. $msg = 'Thanks, please check your mailbox and confirm the subscription.';
  33. $alertclass = 'alert-success';
  34. } else {
  35. if (isset($result['status'])) {
  36. switch ($result['code']) {
  37. case 214:
  38. $msg = 'You\'re already a member of this list.';
  39. break;
  40. // check the MailChimp API if you like to add more options
  41. default:
  42. $msg = 'An unknown error occurred.';
  43. $alertclass = 'alert-error';
  44. break;
  45. }
  46. }
  47.  
  48. }
  49. }
  50. }
  51. ?>
  52.  
  53. <form class="form-horizontal" method="post">
  54. <?php
  55. if ($msg != '') echo '
  56. <div class="alert '.$alertclass.'" role="alert">'.$msg.'</div>';
  57. ?>
  58. <div class="form-group">
  59. <label for="inputName" class="col-sm-2 control-label">First name</label>
  60. <div class="col-sm-10">
  61. <input type="text" class="form-control" name="name" id="inputName">
  62. </div>
  63. </div>
  64. <div class="form-group">
  65. <label for="inputEmail" class="col-sm-2 control-label">Email</label>
  66. <div class="col-sm-10">
  67. <input type="email" class="form-control" name="email" id="inputEmail">
  68. </div>
  69. </div>
  70. <div class="form-group">
  71. <label for="inputMessage" class="col-sm-2 control-label">Message</label>
  72. <div class="col-sm-10">
  73. <textarea class="form-control" rows="3" name="message" id="inputMessage"></textarea>
  74. </div>
  75. </div>
  76. <div class="form-group">
  77. <div class="col-sm-offset-2 col-sm-10">
  78. <div class="checkbox">
  79. <label>
  80. <input type="checkbox" name="newsletter"> Subscribe to newsletter
  81. </label>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="form-group">
  86. <div class="col-sm-offset-2 col-sm-10">
  87. <button type="submit" name="Submit" class="btn btn-default">Submit</button>
  88. </div>
  89. </div>
  90. </form>
RAW Paste Data