Guest User

Untitled

a guest
May 26th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. session_cache_limiter( 'nocache' );
  5. header( 'Expires: ' . gmdate( 'r', 0 ) );
  6. header( 'Content-type: application/json' );
  7.  
  8.  
  9. $email_template = 'simple.html';
  10.  
  11. $subject = strip_tags($_POST['subject']);
  12. $email = strip_tags($_POST['email']);
  13. $phone = strip_tags($_POST['phone']);
  14. $name = strip_tags($_POST['name']);
  15. $empresa = strip_tags($_POST['empresa']);
  16. $message = nl2br( htmlspecialchars($_POST['message'], ENT_QUOTES) );
  17. $result = array();
  18.  
  19. if(empty($name)){
  20.  
  21. $result = array( 'response' => 'error', 'empty'=>'name', 'message'=>'<strong>Error!</strong> Name is empty.' );
  22. echo json_encode($result );
  23. die;
  24. }
  25.  
  26. if(empty($email)){
  27.  
  28. $result = array( 'response' => 'error', 'empty'=>'email', 'message'=>'<strong>Error!</strong> Email is empty.' );
  29. echo json_encode($result );
  30. die;
  31. }
  32.  
  33. if(empty($message)){
  34.  
  35. $result = array( 'response' => 'error', 'empty'=>'message', 'message'=>'<strong>Error!</strong> Message body is empty.' );
  36. echo json_encode($result );
  37. die;
  38. }
  39.  
  40.  
  41. $headers = "From: " . $name . ' <' . $email . '>' . "\r\n";
  42. $headers .= "Reply-To: ". $email . "\r\n";
  43. $headers .= "MIME-Version: 1.0\r\n";
  44. $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  45.  
  46. $templateTags = array(
  47. '{{subject}}' => $subject,
  48. '{{email}}'=>$email,
  49. '{{message}}'=>$message,
  50. '{{name}}'=>$name,
  51. '{{phone}}'=>$phone
  52. );
  53.  
  54. $templateContents = file_get_contents( dirname(__FILE__) . '/email-templates/'.$email_template);
  55.  
  56. $contents = strtr($templateContents, $templateTags);
  57.  
  58. if ( mail( $to, $subject, $contents, $headers ) ) {
  59. $result = array( 'response' => 'success', 'message'=>'<strong>Success!</strong> Mail Sent.' );
  60. } else {
  61. $result = array( 'response' => 'error', 'message'=>'<strong>Error!</strong> Cann\'t Send Mail.' );
  62. }
  63.  
  64. echo json_encode( $result );
  65.  
  66. die;
Advertisement
Add Comment
Please, Sign In to add comment