I have a simple contact form with a PHP email script. I also have a <div> tag that will contain a result message: successful or failure, once the message has been submitted. My problem is that I can't get the message to display within this <div> tag. I'm not real good with PHP so I'm not really sure what I'm doing wrong. Below is the PHP script which is included in my HTML as a separate file. Also, my <form> code is below to.
HTML Code
Thanks,
Code:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$message = $to = $from_email = "";
$to = "info@something.com";
if (empty($_POST["email"])) {
$emailErr = "Email is required";
}
else {
$from_email = $_POST["email"];
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["message"])) {
$emailErr = "Message is required";
}
else {
$message = "\r\n";
$message .= $_POST["message"];
}
$subject = "* * * EMAIL - Inquiry * * *";
// compose headers
$headers = "From: info@something.com\r\n";
$headers .= "Reply-To: info@something.com\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
// compose message
$message = wordwrap($message, 70);
// send email
if (mail($to, $subject, $message, $headers)) {
header('Location: http://www.something.com/#p2');
$_POST['user-message'] = "Thank you...your message has been sent!";
}
else {
echo("Message failure!");
}
}
?>
Code:
<div id="p2" class="boxes">
<div id="contactMe" class="mainDiv">
<h1>Contact Form</h1>
<input id="user-message" name="user-message" style="background-color: #ccc">
<div id="form-messages" style="width: 95%; margin: 5px auto; height: auto"></div>
<form id="ajax-contact" action="scripts/mail3.php" method="POST">
<label for="fullname">Full Name</label>
<input id="name" name="name" type="text" required>
<label for="email">E-Mail</label>
<input id="email" name="email" type="text" required>
<label for="message">Message</label>
<textarea id="message" name="message" rows="3" cols="50" required></textarea>
<button class="button" type="submit">Send E-Mail</button>
</form>
</div>
<div class="backToTop"><a href="#theTop">Back to Top</a></div>
</div>