Created
June 19, 2012 07:37
-
-
Save Riaan-ZA/2952824 to your computer and use it in GitHub Desktop.
PHP Contact Form
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 | |
//Validation | |
$error = ""; | |
//Source Name | |
if ($name == "" or $name == "Name") { | |
$error = "<li>Please enter your name</li>"; | |
} | |
if ($surname == "" or $surname == "Surname") { | |
$error .= "<li>Please enter your surname</li>"; | |
} | |
if ($email1 == "" or $email1 == "Email") { | |
$error .= "<li>Please enter your email address</li>"; | |
} | |
if ($email2 == "Confirm Email") { | |
$error .= "<li>Please enter your email confirmation address</li>"; | |
} | |
if ($email1 != $email2) { | |
$error .= "<li>Please make sure the two email addresses match</li>"; | |
} | |
if ($phone == "") { | |
$error .= "<li>Please enter your phone number</li>"; | |
} | |
if ($answer == "") { | |
$error .= "<li>Please answer the competition question</li>"; | |
} | |
if ($terms != "agreed") { | |
$error .= "<li>Please agree tick the checkbox to agree to the terms and conditions</li>"; | |
} | |
if (empty($error)) { | |
require("class.phpmailer.php"); | |
///////////////////////////////////////////////// | |
//Admin Email | |
///////////////////////////////////////////////// | |
$mail = new PHPMailer(); // defaults to using php "mail()" | |
$body = "<p>New Competition Entrant Details:</p> | |
<p> | |
<b>Name:</b> ".$name . "<br /> | |
<b>Surname:</b> ".$surname."<br /> | |
<b>Email Address:</b> ".$email1."<br /> | |
<b>Phone Number:</b> ".$phone." | |
</p>"; | |
$mail->AddAddress("[email protected]"); | |
$mail->AddReplyTo("[email protected]","Apartment SA - Facebook"); | |
$mail->SetFrom("[email protected]","Apartment SA - Facebook"); | |
$mail->Subject = "New Apartment SA facebook competition entry"; | |
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //optional, comment out and test | |
$mail->MsgHTML($body); | |
if(!$mail->Send()) { | |
$error .= "<span class='error'>Error sending mail.</span>"; | |
} else { | |
$success = TRUE; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment