Skip to content

Instantly share code, notes, and snippets.

@albertodelax
Last active August 29, 2015 14:25
Show Gist options
  • Save albertodelax/1449e618c032000456f1 to your computer and use it in GitHub Desktop.
Save albertodelax/1449e618c032000456f1 to your computer and use it in GitHub Desktop.
Simple HTML contact form with PHP
<?php
$EmailFrom = Trim(stripslashes($_POST['email']));
$EmailTo = "agdelax@gmail.com";
$Subject = Trim(stripslashes($_POST['subject']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $Subject;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
// var_dump($_POST);
?>
<html>
<head>
<style type="text/css">
input {
display: block;
margin: 5px;
}
textarea {
margin: 0 0 0 5px;
width: 131px;
height: 100px;
}
p {
font: 12px sans-serif;
margin: 0 0 0 5px;
}
</style>
</head>
<body>
<p>Contact Form</p>
<form name="htmlform" method="post" action="email-form.php">
<input type="email" name="email" placeholder="Enter email">
<input type="text" name="subject" placeholder="Enter subject">
<textarea id="message" type="text" name="message" placeholder="Enter message"></textarea>
<input type="submit" value="Submit">
</form>
</body>
</html>
<html>
<body>
<p>Thank you!</p>
<p>Please leave.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment