elocs Posted November 17, 2017 Share Posted November 17, 2017 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 = "cole.shannon3@gmail.com"; 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; }); Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 17, 2017 Share Posted November 17, 2017 Windows does not have SMTP. If you just want to check the mail sending you can use https://smtp4dev.codeplex.com/ Quote Link to comment Share on other sites More sharing options...
Barand Posted November 17, 2017 Share Posted November 17, 2017 (edited) Windows does not have SMTP. Erm, https://technet.microsoft.com/en-us/library/cc772058(v=ws.10).aspx Edited November 17, 2017 by Barand Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 17, 2017 Share Posted November 17, 2017 Erm, not sure what your 404 link was supposed to be but I was assuming OP is on Win7-10. Hows this.. Windows does not have SMTP on win 7-10 by default. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 17, 2017 Share Posted November 17, 2017 Not by default, but same goes for IIS too. SMTP can be configured under IIS. That was supposed to be a link to the instructions. Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 17, 2017 Share Posted November 17, 2017 (edited) Got it, but yes it can be done in IIS. If you look at OPs post, he is using XAMPP which has an SMTP but needs to be configured to work. Edited November 17, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 18, 2017 Share Posted November 18, 2017 Getting back to the OP's post - Is that really how you assemble your code? Html, PHP, JQ, Html..... Very ahrd to follow. How about organizing the script's contents into the proper logically oriented pieces that they are and perhaps we (me perhaps) can help you diagnose this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.