Guest User

Send mail notification if user subscribes to sendy

a guest
Aug 27th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2.     //------------------- Edit here --------------------//
  3.     $sendy_url = 'http://your.sendy.installation';
  4.     $list = $_POST['list'];
  5.     //------------------ /Edit here --------------------//
  6.  
  7.     //--------------------------------------------------//
  8.     //POST variables
  9.     $name = $_POST['name'];
  10.     $email = $_POST['email'];
  11. //url2 is used not let spammers subscribe by putting a hidden field in the form.
  12.     $url2 = $_POST['url2'];
  13. //put here any other custom fields you have in the same way as url2 or email or name. Make sure the name in the [''] matches the id of the input field from the html and js file
  14.  
  15.       //subscribe, put here all the other custom fields. I didn't put url2 because it's only used in this php to check if it's filled
  16.     $postdata = http_build_query(
  17.         array(
  18.         'name' => $name,
  19.         'email' => $email,
  20.         'list' => $list,
  21.         'boolean' => 'true'
  22.         )
  23.     );
  24.     $opts = array('http' => array('method'  => 'POST', 'header'  => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
  25.     $context  = stream_context_create($opts);
  26.     $result = file_get_contents($sendy_url.'/subscribe', false, $context);
  27.    
  28. //if url2 is completed, don't subscribe (but it gives a success message to the bot (in the .js script)
  29.     if($url2) {
  30.     echo "nu merge";
  31.      }
  32.     else {echo $result;
  33. //you can erase this part if you only want to check for spammers but not send an email notification
  34.     $message = "You have a new subscriber with the following details:\n";
  35.  
  36.  
  37. // Send
  38. if($result == "1") {
  39. //you can add more custom fields with the . (dot) function.
  40. mail('[email protected]', 'Subject of the email', $message.$name."\n".$email); }
  41. //erase until here if you don't want to send mail notification
  42.     };
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment