Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2.  
  3. // Email address verification
  4. function isEmail($email) {
  5. return filter_var($email, FILTER_VALIDATE_EMAIL);
  6. }
  7.  
  8. if($_POST) {
  9.  
  10. $mailchimp_api_key = 'mojapi'; // enter your MailChimp API Key
  11. // ****
  12. $mailchimp_list_id = 'list id'; // enter your MailChimp List ID
  13. // ****
  14.  
  15. $subscriber_email = addslashes(trim($_POST['email']));
  16.  
  17. if(!isEmail($subscriber_email)) {
  18. $array = array();
  19. $array['valid'] = 0;
  20. $array['message'] = 'Not a valid email address!';
  21. echo json_encode($array);
  22. }
  23. else {
  24. $array = array();
  25. $merge_vars = array();
  26.  
  27. require_once 'MailChimp.php';
  28.  
  29. $MailChimp = new \Drewm\MailChimp($mailchimp_api_key);
  30. $result = $MailChimp->call('lists/subscribe', array(
  31. 'id' => $mailchimp_list_id,
  32. 'email' => array('email' => $subscriber_email),
  33. 'merge_vars' => $merge_vars,
  34. 'double_optin' => true,
  35. 'update_existing' => true,
  36. 'replace_interests' => false,
  37. 'send_welcome' => false,
  38. ));
  39.  
  40. if($result == false) {
  41. $array['valid'] = 0;
  42. $array['message'] = 'An error occurred! Please try again later.';
  43. }
  44. else {
  45. $array['valid'] = 1;
  46. $array['message'] = 'Success! Please check your mail.';
  47. }
  48.  
  49. echo json_encode($array);
  50.  
  51. }
  52.  
  53. }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement