Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. <?php
  2. // Check for empty fields
  3. if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
  4. echo json_encode(array('error'=>'true'));
  5. return false;
  6. }
  7.  
  8. $name = $_POST['name'];
  9. $email_address = $_POST['email'];
  10. $message = $_POST['message'];
  11.  
  12. $lastname = $_POST['lastname'];
  13. $phone = $_POST['phone'];
  14. $subject = ($_POST['subject'] ? $_POST['subject'] : "Website Contact Form: $name");
  15.  
  16.  
  17.  
  18. // Create the email and send the message
  19. $to = 'email@to.com.br';// Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
  20. $email_subject = $subject;
  21. $email_body = "You have received a new message from your website contact form.nn"."Here are the details:nnName: $namennLast Name: $lastnamennEmail: $email_addressnnPhone: $phonennMessage:n$message";
  22. $headers = "From: noreply@yourdomain.comn"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
  23. $headers .= "Reply-To: $email_address";
  24. mail($to,$email_subject,$email_body,$headers);
  25. echo json_encode(array('success'=>'true'));
  26. return true;
  27. ?>
  28.  
  29. <?php
  30. ini_set('display_errors', '1');
  31. header("Content-Type: application/json; charset=utf-8");
  32. require("phpmailer/class.phpmailer.php");
  33. require("phpmailer/class.smtp.php");
  34.  
  35. // Check for empty fields
  36. if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
  37. echo json_encode(array('error'=>'true'));
  38. return false;
  39. }
  40.  
  41. $mail = new PHPMailer();
  42.  
  43. $mail->IsSMTP();
  44. $mail->SMTPAuth = true; // Usar autenticação SMTP (obrigatório para smtp.seudomínio.com.br)
  45. $mail->Username = 'leadsvw@grupomenegalli.com.br'; // Usuário do servidor SMTP (endereço de email)
  46. $mail->Password = '*********'; // Senha do servidor SMTP (senha do email usado)
  47.  
  48. $mail->From = "leadsvw@grupomenegalli.com.br"; // Seu e-mail
  49. $mail->Sender = "leadsvw@grupomenegalli.com.br"; // Seu e-mail
  50. $mail->FromName = "Dimasa VW"; // Seu nome
  51.  
  52. $mail->AddAddress('leadsvw@grupomenegalli.com.br', 'Dimasa');
  53.  
  54. $mail->IsHTML(true);
  55.  
  56. $name = $_POST['name'];
  57. $email_address = $_POST['email'];
  58. $message = $_POST['message'];
  59.  
  60. $lastname = $_POST['lastname'];
  61. $phone = $_POST['phone'];
  62.  
  63. $mail->Subject = "Contato a partir do site Dimasa VW";
  64.  
  65. $message = "
  66. <html>
  67. <head>
  68. <title>Contato a partir do site Dimasa VW</title>
  69. </head>
  70. <body>
  71.  
  72. <p>
  73. Nome: $name<br>
  74.  
  75. Email: $email_address<br>
  76.  
  77. Telefone: $phone<br>
  78.  
  79. Mensagem: $message
  80. </p>
  81. </body>
  82. </html>
  83. ";
  84.  
  85. $mail->Body = $message;
  86. $xx = $mail->Send();
  87.  
  88. $mail->ClearAllRecipients();
  89. $mail->ClearAttachments();
  90.  
  91. if($xx){
  92. echo json_encode(array('success'=>'true'));
  93. return true;
  94. }
  95. ?>
  96.  
  97. $(function() {
  98. $("input,textarea").jqBootstrapValidation({
  99. preventSubmit: true,
  100. submitError: function($form, event, errors) {
  101. // additional error messages or events
  102. },
  103. submitSuccess: function($form, event) {
  104. event.preventDefault(); // prevent default submit behaviour
  105. // get values from FORM
  106. var topic = $("select#user-topic").val();
  107. var name = $("input#user-name").val();
  108. var email = $("input#user-email").val();
  109. var phone = $("input#user-phone").val();
  110. var message = $("textarea#user-message").val();
  111. var firstName = name; // For Success/Failure Message
  112. // Check for white space in name for Success/Fail message
  113. if (firstName.indexOf(' ') >= 0) {
  114. firstName = name.split(' ').slice(0, -1).join(' ');
  115. }
  116. $.ajax({
  117. url: "../../mail/contact_me.php",
  118. type: "POST",
  119. dataType: 'json',
  120. data: {
  121. topic: topic,
  122. name: name,
  123. email: email,
  124. phone: phone,
  125. message: message
  126. },
  127. cache: false,
  128. success: function(data) {
  129. if(data.error){
  130. // Fail message
  131. $('#success').html("<div class='alert alert-danger'>");
  132. $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;").append("</button>");
  133. $('#success > .alert-danger').append("<span>Perdão " + firstName + ", parece que ocorreu uma falha no envio, tente novamente!</span>");
  134. $('#success > .alert-danger').append('</div>');
  135. //clear all fields
  136. $('#contactForm').trigger("reset");
  137. }
  138. else if(data.success){
  139. // Success message
  140. $('#success').html("<div class='alert alert-success'>");
  141. $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;").append("</button>");
  142. $('#success > .alert-success').append("<span>Sua mensagem foi enviada com sucesso </span>");
  143. $('#success > .alert-success').append('</div>');
  144. //clear all fields
  145. $('#contactForm').trigger("reset");
  146. }
  147. }
  148. })
  149. },
  150. filter: function() {
  151. return $(this).is(":visible");
  152. },
  153. });
  154. });
  155.  
  156.  
  157. /*When clicking on Full hide fail/success boxes */
  158. $('#name').focus(function() {
  159. $('#success').html('');
  160. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement