1

I'm using the Remodal plugin to show modals on my website. (https://github.com/VodkaBears/Remodal) This works great for my needs. This is the first time I'm working with modals and e-mail forms. I have a script to submit the form, and it looks like this;

<form name="contact" id="contact" class="contact" method="post">
    <label for="name">
        <span>Name</span>
        <input type="text" name="name" required="true" />
    </label>
    <label for="email">
        <span>Email</span>
        <input type="email" name="email" required="true" />
    </label>
    <label for="phone">
        <span>Phone</span>
        <input type="text" name="phone" required="true" />
    </label>
    <label for="message">
        <span>Your message</span>
        <textarea name="message" required="true">    </textarea>
    </label>
    <label>
        <br>
        <span>&nbsp;</span>
        <input type="submit" class="send" value="Send"/>
    </label>
</form>

And this is my script for submitting the form;

$(document).on('click', '.send', function () {
    $.ajax({
        type: "POST",
        url: "mail.php",
        data: $('form.contact').serialize(),
        success: function (msg) {
            $("#thanks").html(msg)
            $("form.contact").modal('hide');
        },
        error: function () {
            alert("Error.");
        }
    });
    return false;
});

Mail.php:

<?php 
//if "email" variable is filled out, send email 
if (isset($_REQUEST['email'])) { 
    //Email information 
    $admin_email = "my@email.com"; 
    $name = $_REQUEST['name']; 
    $email = $_REQUEST['email']; 
    $phone = $_REQUEST['phone']; 
    $message = $_REQUEST['message']; 

    //send email 
    mail($admin_email, "New e-mail", $message, "From:" . $email); 
    //Email response 
    echo "Thank you!"; 
} 
?> 

I found this code somewhere, and I'm trying to implement it to my form. It works! However, I don't get any success message or error messages with this. I'm trying to wrap my head arond it, but can't figure it out. Can someone help?

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
zorensen
  • 334
  • 4
  • 19

0 Answers0