I have a basic Contact form for my website, but I can not get it to work. The form acts like it is sending, but I never received the email from the form. It is using twitter bootstrap. I got the initial code from freehtml template. I have the form uploaded at www.tonyaespinoza.com/walnut/contact.html as a temporary location so I could have it uploaded to a server for testing.
Here is the HTML form:
<div class="col-md-6">
<form method="post" name="contactForm" role="form" id="contactForm"
action="sendEmail.php">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="message" id="message" name="message" cols="30" rows="10"
class="form-control"></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn btn-special" value="Send Message">
<div class="submitting"></div>
</div>
</form>
<div id="form-message-warning"></div>
<div id="form-message-success">
Your message was sent, thank you!</div>
</div>
And here is the php:
$to = 'my_mail@yahoo.com';
function url(){
return sprintf(
"%s://%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['SERVER_NAME']
);
}
if($_POST) {
$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$contact_message = trim(stripslashes($_POST['message']));
if ($subject == '') { $subject = "Contact Form Submission"; }
// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= nl2br($contact_message);
$message .= "<br /> ----- <br /> This email was sent from your site " .
url() . " contact form. <br />";
// Set From: header
$from = $name . " <" . $email . ">";
// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
ini_set("sendmail_from", $to); // for windows server
$mail = mail($to, $subject, $message, $headers);
if ($mail) { echo "OK"; }
else { echo "Something went wrong. Please try again."; }
}
?>