Advertisement
renanxusa

Untitled

Oct 25th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <?php
  2. /*
  3. * Email settings
  4. */
  5. // admin email
  6. $adminEmail = 'contato@locusmap.com.br';
  7. // email will arrive from
  8. $fromEmail = 'formulario@locusmap.com';
  9. // message subject
  10. $subject = 'Mensagem do site';
  11. // message intro
  12. $message = "Mensagem do formulário";
  13. /*
  14. * Validation settings
  15. */
  16. // required
  17. $required = array('name','email','message','captcha');
  18. // valid email
  19. $validEmail = array('email');
  20.  
  21. // Do validation
  22. $res = array('result'=>true,'errors'=>array());
  23. if(!empty($_POST)){
  24. foreach ($_POST as $key => $value) {
  25. if(in_array($key, $required)){ // check if required
  26. if(trim($value) == ''){ // check if empty
  27. $res['result'] = false;
  28. if(!isset($res['errors'][$key])) // don't set more than one error
  29. $res['errors'][$key] = 'required';
  30. }
  31. }
  32.  
  33. if(in_array($key, $validEmail)){ // check if required
  34. $pattern = '/^[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}$/';
  35.  
  36. if(preg_match($pattern, $value) === 0){ // check if empty
  37. $res['result'] = false;
  38. if(!isset($res['errors'][$key])) // don't set more than one error
  39. $res['errors'][$key] = 'email';
  40. }
  41. }
  42. }
  43.  
  44. if($res['result'] === true){ //validation passed
  45. // message content
  46. require 'PHPMailerAutoload.php';
  47.  
  48. $mail = new PHPMailer;
  49.  
  50. //$mail->SMTPDebug = 3; // Enable verbose debug output
  51.  
  52. $mail->isSMTP(); // Set mailer to use SMTP
  53. $mail->Host = 'smtp.umbler.com'; // Specify main and backup SMTP servers
  54. $mail->SMTPAuth = true; // Enable SMTP authentication
  55. $mail->Username = 'contato@locusmap.com.br'; // SMTP username
  56. $mail->Password = 'geografiauerj16'; // SMTP password
  57. $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
  58. $mail->Port = 587; // TCP port to connect to
  59.  
  60. $mail->setFrom('formulario@locusmap.com.br', $_POST['name']);
  61. $mail->addAddress('contato@locusmap.com.br'); // Add a recipient
  62. $mail->addAddress('ellen@example.com'); // Name is optional
  63. $mail->addReplyTo($_POST['email']);
  64.  
  65. $mail->isHTML(true); // Set email format to HTML
  66.  
  67. $mail->Subject = 'Email enviado pelo site';
  68. $mail->Body = $_POST['message'];
  69.  
  70. if(!$mail->send()) {
  71. echo 'A mensagem voltou.';
  72. echo 'Mailer Error: ' . $mail->ErrorInfo;
  73. } else {
  74. echo 'A mensagem foi enviada!';
  75. }
  76. }
  77. }
  78.  
  79. echo json_encode($res);
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement