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>