Guest User

Untitled

a guest
Mar 30th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. <?php
  2. if($_POST)
  3. {
  4. $to_email = "[email protected]"; //Recipient email, Replace with own email here
  5.  
  6. //check if its an ajax request, exit if not
  7. if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
  8.  
  9. $output = json_encode(array( //create JSON data
  10. 'type'=>'error',
  11. 'text' => 'Sorry Request must be Ajax POST'
  12. ));
  13. die($output); //exit script outputting json data
  14. }
  15.  
  16. //Sanitize input data using PHP filter_var().
  17. $name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
  18. $email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
  19. $message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
  20. $from = '[email protected]'; // Sender of contacts form emails
  21. $subject = 'New Subscriber'; // Set the subject of email which you will receive
  22.  
  23. //email body
  24. $message_body = $message."\r\n\r\n-".$name."\r\nEmail : ".$email;
  25.  
  26. //proceed with PHP email.
  27. $headers = 'From: '.$from.'' . "\r\n" .
  28. 'X-Mailer: PHP/' . phpversion();
  29.  
  30. $send_mail = @mail($to_email, $subject, $message_body, 'Message sent via contact form '.$email , $headers);
  31.  
  32. if(!$send_mail)
  33. {
  34. //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
  35. $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
  36. die($output);
  37. }else{
  38. $output = json_encode(array('type'=>'message', 'text' => 'Hi '.$name .'! Thank you for your email'));
  39. die($output);
  40. }
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment