Jump to content

Contact Form


elocs

Recommended Posts

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">
 
 
 
 
 
</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;
});
 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.