Last active
August 29, 2015 14:25
-
-
Save albertodelax/1449e618c032000456f1 to your computer and use it in GitHub Desktop.
Simple HTML contact form with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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