Skip to content

Instantly share code, notes, and snippets.

@nhudesign
Last active March 4, 2016 16:02
Show Gist options
  • Save nhudesign/e1ee52b441e2db8395b1 to your computer and use it in GitHub Desktop.
Save nhudesign/e1ee52b441e2db8395b1 to your computer and use it in GitHub Desktop.
Contact form on an HTML website
<form class="form" action="mail.php" method="post">
<!-- Name Field Start -->
<div class="name">
<input type="text" placeholder="YOUR NAME" name="name">
</div>
<!-- Name Field End -->
<!-- Email Start -->
<div class="email">
<input type="email" placeholder="YOUR EMAIL" name="email">
</div>
<!-- Email End -->
<!-- Meaasage Start -->
<div class="message">
<textarea placeholder="YOUR MESSAGE" name="message"></textarea>
</div>
<!-- Message End -->
<!-- Submit Button -->
<button type="submit" value="send">submit</button>
</form>
<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "hello@nhudesign.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
if( mail ($recipient, $message, $name, "From: $email")){
header("Location: submit.html");
}
else {
echo "Something messed up! :( <br> Send your message to hello@nhudesign.com, and I'll be sure to get back to you!<br><br>Name: $name<br>E-mail: $email<br>Comment:<br>$comment";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment