Code: Select all
<?php
include('inc/connection_request.php');
if(isset($_POST['submit'])) { // if form is submitted
$returned_message = ""; // Sets message to empty.
/**********
Validate form data.
***********/
// Email
if(empty($_POST['email'])) {
$email = FALSE;
$returned_message .= "You must enter your Email Address<br />";
} else {
// Set email variable
$email = $_POST['email'];
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("@",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$email = $_POST['email'];
} else {
$email = FALSE;
$returned_message .= "You must enter a valid Email Address<br />";
}
}
/**********
Place data in DB
***********/
if ($email) {
$query = "INSERT INTO Contest (first_name, last_name, email, age, address, city, zipcode, phone, youtube_a, youtube_b, youtube_c, youtube_d, youtube_e, alternate, submit_date)
VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[email]', '$_POST[age]', '$_POST[address]', '$_POST[city]', '$_POST[zipcode]', '$_POST[phone]', '$_POST[youtube_a]', '$_POST[youtube_b]', '$_POST[youtube_c]', '$_POST[youtube_d]', '$_POST[youtube_e]', '$_POST[alternate]', (CURRENT_TIMESTAMP))";
$result = @mysql_query($query);
if($result) {
$addres = $email;
$headers = 'BCC: rom.matt@gmail.com';
$addresses = "$addres";
$subject = 'Oregon School Choice Video Contest Entry';
$mailcontent = "Your contest information has been received."
."\n\n==================\n\n"
."Name:\t\t".$first_name." ".$last_name."\n"
."Email:\t\t".$email."\n\n"
."Age:\t\t".$age."\n"
."Mailing Address:\t\t\t".$address."\n"
."City:\t\t\t".$city."\n"
."Zip:\t\t\t".$zipcode."\n"
."Phone:\t".$phone."\n"
."==================\n\n"
."First YouTube URL:\t\t".$youtube_a."\n"
."Second YouTube URL:\t\t".$youtube_b."\n"
."Third YouTube URL:\t\t".$youtube_c."\n"
."Fourth YouTube URL:\t\t".$youtube_d."\n"
."Fifth YouTube URL:\t\t".$youtube_e."\n"
."==================\n\n"
."Alternate means of delivery:\t\t".$alternate."\n\n";
$fromaddress = 'From: '.$email;
$mail_sent = mail($addresses, $subject, $mailcontent, $fromaddress, $headers);
if($mail_sent) {
$win_message .= 'Your entry information has been received.<br />
We will contact you once your content has been approved.<br />';
}
} else {
$returned_message .= "Problem inserting";
}
}
}
?>