dimanche 3 mai 2015

Submitting form and success message on same page?

So right now I have a basic contact.html with a php script set to email me if someone on my website contacts me. When they click submit, it takes them to contact_sent.php, which is a blank page. I want it so that when they click the submit, it keeps them on the same page, as well as display a success message from SweetAlert, and then clear the form so they can't spam the "Send Message" button.

<?php
if($_POST['submit']) {
    $name=$_POST['name'];
    $email=$_POST['email'];
    $subject=$_POST['subject'];
    $message=$_POST['msg'];
    $to_add="***********@gmail.com";
    $from_add="form@***********.net";

    $email_message="<br /><br /><b>Name:</b><br />$name <br />";
    $email_message.="<br /><br /><b>Reply Email:</b><br />$email <br />";
    $email_message.="<br /><br /><b>Regarding:</b><br />$subject <br />";
    $email_message.="<br /><br /><b>Message:</b><br />$message <br />";

    $headers="From: $from_add \r\n";
    $headers.="Reply-To: $from_add \r\n";
    $headers.="Return-Path: $from_add\r\n";
    $headers.="X-Mailer: PHP \r\n";
    $headers.="MIME-Version: 1.0\r\n";
    $headers.="Content-Type: text/html;\r\n";

    mail($to_add,$subject,$email_message,$headers);
}
alert("Sent!");
?>

Edit: The alert at the end doesn't work.

Aucun commentaire:

Enregistrer un commentaire