I am just trying to create a contact form and send it to myself. I get this error when I hit the submit button : Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\pet-shop\pet-shop\send-mail.php on line 9
$('#submit').on('click', function(){ // get form values and compose a data string var name = $("#name").val(); var email = $("#email").val(); var message = $("#message").val(); var data ='name=' + name + '&email=' + email + '&message=' + message; // AJAX call passing dataString in POST $.ajax({ type: 'POST', data: data, url: 'send-mail.php', success: function(){ // success callback console.log('message sent! :D'); } }); // prevent the default submit action return false; });
Here is my code:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Contact US</title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<?php include("includes/header.html");?>
<form name="my-form" method="POST" action="send-mail.php">
<input type="text" id="name" name="name" value="" placeholder="Name" />
<input type="email" id="email" name="email" value="" placeholder="E-mail" />
<textarea id="message" name="message"></textarea>
<input type="submit" id="submit" value="SUBMIT" name="submit" />
</form>
<?php include("includes/footer.html");?>
</body>
</html>
<?php
$to = "
[email protected]";
if($_POST){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
mail($to, "New message from " . $name, $message, "From: $email" );
}
?>
$('#submit').on('click', function(){
// get form values and compose a data string
var name = $("#name").val();
var email = $("#email").val();
var message = $("#message").val();
var data ='name=' + name + '&email=' + email + '&message=' + message;
// AJAX call passing dataString in POST
$.ajax({
type: 'POST',
data: data,
url: 'send-mail.php',
success: function(){
// success callback
console.log('message sent! :D');
}
});
// prevent the default submit action
return false;
});