Guest User

Untitled

a guest
Dec 16th, 2018
227
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. $toName = 'Emerson Carvalho';
  4. $toEmail = 'abc@abc.com.br';
  5.  
  6.  
  7. $name = '';
  8. $email = '';
  9. $phone = '';
  10. $subject = '';
  11. $message = '';
  12.  
  13. $return = array( 'status' => null, 'msg' => null);
  14.  
  15. if(isset($_POST['form']) && empty($_POST['form'])){
  16.  
  17.  
  18. $name = trim($_POST['name']);
  19. $email = trim(strtolower($_POST['email']));
  20. $phone = trim($_POST['phone']);
  21. $subject = trim($_POST['subject']);
  22. $message = $_POST['message'];
  23.  
  24. $async = ( isset($_POST['type']) && $_POST['type'] == 'async' );
  25.  
  26.  
  27. //Format message
  28. $content = '<h1>Contato Site</h1>';
  29. $content.= sprintf('<strong>Nome</strong>: %s<br/>', $name);
  30. $content.= sprintf('<strong>Email</strong>: %s<br/>', $email);
  31. $content.= sprintf('<strong>Telefone</strong>: %s<br/>', $phone);
  32. $content.= sprintf('<strong>Assunto</strong>: %s<br/>', $subject);
  33. $content.= sprintf('<strong>Mensagem</strong>:<br/> %s<br/>', $message);
  34. $content.= sprintf('<small>enviado em: %s</small><br/>', date('d/m/Y - H:i:s'));
  35.  
  36. if(isset($_SERVER['HTTP_REFERER']))
  37. $content.= sprintf('<small>%s</small><br/>', $_SERVER['HTTP_REFERER']);
  38.  
  39.  
  40. $newline = "\r\n";
  41.  
  42. // To send HTML mail, the Content-type header must be set
  43. $headers = 'MIME-Version: 1.0' . $newline;
  44. $headers .= 'Content-type: text/html; charset=iso-8859-1' . $newline;
  45.  
  46. // Additional headers
  47. $headers .= sprintf('To: %s <%s>', $toName, $toEmail ) . $newline;
  48. $headers .= sprintf('From: %s <%s>', $name, $email ) . $newline;
  49.  
  50. // Mail it
  51. $sent = mail($toEmail, $subject, $content, $headers);
  52. if($sent){
  53.  
  54. $name = '';
  55. $email = '';
  56. $message = '';
  57. $phone = '';
  58.  
  59. $return['status'] = 'ok';
  60. $return['msg'] = 'Contato enviado com sucesso';
  61.  
  62. }else{
  63. $return['status'] = 'error';
  64. $return['msg'] = 'Contato enviado com sucesso';
  65. }
  66.  
  67. if( $async )
  68. {
  69. echo json_encode($return);
  70. die();
  71. }
  72.  
  73. }
  74.  
  75. ?>
Add Comment
Please, Sign In to add comment