0

I´m having trouble with my contact form, after submit form i don't recive any mail. When i used other hosting platform it worked just fine, so it's seems to be a problem with my current provider, i have contacted them but they only suggested to use PhPMailer but i don't understand how to set it up. Is there a way to change my code to work just fine?

mail.php file:

<?php

$frm_name  = "John Doe"; //your name
$recepient = "xyz@gmail.com"; //your e-mail
$sitename  = "John Doe Site"; //your site name
$subject   = "New contact from \"$sitename\""; //subject template

$name = trim($_POST["visitor_name"]);
$email = trim($_POST["visitor_email"]);
$msg = trim($_POST["visitor_msg"]);

$message = "
-------------------<br><br>
Visitor name: $name <br>
Visitor email: $email <br><br>
$msg
<br><br>-------------------
";

mail($recepient, $subject, $message, "From: $name <$recepient>" . "\r\n" . "Reply-To: $recepient" . "\r\n" . "X-Mailer: PHP/" . phpversion() . "\r\n" . "Content-type: text/html; charset=\"utf-8\"");
?>

mail.js file:

// form handling
   $('.form-contact').submit(function(e) {
       e.preventDefault();
       // validity polyfill for Safari browser
       if (!e.target.checkValidity()) {
           alert('Please fill out the required fields.'); // error message
       } else {
           $.ajax({
               type: 'POST',
               url: 'mail.php',
               data: $(this).serialize()
           }).done(function() {
               setTimeout(function() {
                   alert('Thanks for your message! I will reply you as soon as possible.');
               }, 1500);
           }).fail(function() {
               setTimeout(function() {
                   alert('Something went wrong :( Please contact me directly to my email.');
               }, 1500);
           });
       }

   });

Html code:

<form action="mail.php" method="POST" class="form-contact">
  <input type="text" name="visitor_name" placeholder="Your Name *" required>
  <input type="email" name="visitor_email" title="Please enter a valid e-mail like user@example.com" placeholder="Your E-mail *" required>
  <textarea name="visitor_msg" placeholder="Your Message..."></textarea>
  <input type="submit" value="Send message" class="btn btn-cta">
</form>
Ionut Necula
  • 11,107
  • 4
  • 45
  • 69
Swipr
  • 1
  • 3
  • If it works on one server but not another, make sure they don't have a restriction on the From address. Some servers will only allow the From address to be your domain to prevent abuse. – aynber Nov 29 '16 at 14:38
  • PHPMailer is very easy, have you read this documentation https://github.com/PHPMailer/PHPMailer. There is a simple example right there on that page that can help you. – Ionut Necula Nov 29 '16 at 14:41

0 Answers0