-
-
Save sdellis/2911722 to your computer and use it in GitHub Desktop.
PHP mail() contact form script
This file contains hidden or 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 | |
if(isset($_POST['submit'])) { | |
if(trim($_POST['name']) == '') { | |
$hasError = true; | |
} else { | |
$name = trim($_POST['name']); | |
} | |
if(trim($_POST['subject']) == '') { | |
$hasError = true; | |
} else { | |
$subject = trim($_POST['subject']); | |
} | |
if(trim($_POST['email']) == '') { | |
$hasError = true; | |
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { | |
$hasError = true; | |
} else { | |
$email = trim($_POST['email']); | |
} | |
if(trim($_POST['message']) == '') { | |
$hasError = true; | |
} else { | |
if(function_exists('stripslashes')) { | |
$comments = stripslashes(trim($_POST['message'])); | |
} else { | |
$comments = trim($_POST['message']); | |
} | |
} | |
if(!isset($hasError)) { | |
$emailTo = '[email protected]'; | |
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; | |
$headers = 'From: Message from REAL contact form <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; | |
mail($emailTo, $subject, $body, $headers); | |
$emailSent = true; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>REAL Hostel Work - Contact</title> | |
<meta name="description" content="Enabling independent backpackers to have a real South American hostel work exchange experience, fully immersed in local culture, focused on volunteerism and in keeping with eco-friendly and green practices."> | |
<meta name="keywords" content="REAL, real, hostel, work, South America, Latin, experience, green, eco, eco-friendly, budget"> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<link rel="stylesheet" href="../css/styles.css"> | |
<link rel="icon" href="../img/favicon.png" type="image/png"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script> | |
<script src="../scripts/jquery.validate.min.js"></script> | |
</head> | |
<body> | |
<div id="header" class="clearFix"> | |
<a class="logo" href="http://www.realhostelwork.com"></a> | |
<h1>REAL<span>Hostel Work</span></h1> | |
<h2>Real Experiences América Latina</h2> | |
<ul id="primaryNav" class="clearFix"> | |
<li><a href="../programs/">Programs</a></li> | |
<li><a href="#">Blog</a></li> | |
<li><a href="../green/">Green</a></li> | |
<li><a href="../contact/" class="active">Contact</a></li> | |
</ul> | |
</div> | |
<div id="wrapper" class="clearFix"> | |
<div class="contentLight clearFix"> | |
<h3>Contact</h3> | |
<?php if(isset($hasError)) { ?> | |
<p class="error">Please check that you've filled all the fields with valid information.</p> | |
<?php } ?> | |
<?php if(isset($emailSent) && $emailSent == true) { ?> | |
<p class="success">Thank you for getting in touch, <?php echo $name;?>! We'll get back to you soon.</p> | |
<?php } ?> | |
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contact"> | |
<fieldset> | |
<label for="name">Name</label> | |
<input type="text" id="name" name="name" class="required" required> | |
</fieldset> | |
<fieldset> | |
<label for="email">Email</label> | |
<input type="text" id="email" name="email" class="required email" required> | |
</fieldset> | |
<fieldset> | |
<label for="subject">Subject</label> | |
<input type="text" id="subject" name="subject"> | |
</fieldset> | |
<fieldset> | |
<label for="message">Message</label> | |
<textarea id="message" name="message" class="required" required></textarea> | |
</fieldset> | |
<fieldset> | |
<input type="submit" name="submit" value="Send"> | |
</fieldset> | |
</form> | |
</div> | |
<div id="footer" class="clearFix"> | |
<div class="footerCol"> | |
<h6>REAL Hostel Work</h6> | |
<ul> | |
<li><a href="http://www.realhostelwork.com">Home</a></li> | |
<li><a href="../programs">Programs</a></li> | |
<li><a href="#">Blog</a></li> | |
<li><a href="../green">Green</a></li> | |
<li><a href="../contact">Contact</a></li> | |
</ul> | |
</div> | |
<div class="footerCol"> | |
<h6>Find us on...</h6> | |
<ul> | |
<li><a href="https://www.facebook.com/REALhostelworkexchange">Facebook</a></li> | |
<li><a href="https://twitter.com/#!/realhostelwork">Twitter</a></li> | |
<li><a href="https://plus.google.com/112503986278486913723">Google+</a></li> | |
</ul> | |
</div> | |
<div class="footerCol"> | |
<h6>Affiliates</h6> | |
<ul> | |
<li><a href="http://www.holahostels.com/">HoLa!</a></li> | |
<li><a href="http://www.worldnomads.com">World Nomads</a></li> | |
</ul> | |
</div> | |
<div id="copy"> | |
<p>Site by <a href="http://www.mikebabb.com">Mike Babb</a></p> | |
<p class="bold">© REAL Hostel Work <script type="text/javascript">document.write(new Date().getFullYear());</script></p> | |
</div> | |
</div> | |
</div> | |
</body> | |
<script src="../scripts/validateForm.js"></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment