HTML Form Code
- Code: Select all
<form action="contestmailer.php" method="post" id="contactform">
<ol>
<li>
<label for="name">Full Name <span class="red">(required)</span></label>
<input id="name" name="name" class="text" />
</li>
<li>
<label for="email">Your email <span class="red">(required)</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="coupon">Coupon Name <span class="red">(required)</span></label>
<input id="coupon" name="coupon" class="text" />
</li>
<li>
<label for="dog">Dog Name <span class="red">(required)</span></label>
<input id="dog" name="dog" class="text" />
</li>
<li class="buttons">
<input type="image" name="imageField" id="imageField" src="images/send.gif" class="send" />
<div class="clr">By submitting the form you agree to the <a href="Character Contest Rules.pdf">Contest Rules</a></div>
</li>
</ol>
</form>
PHP mailer code
- Code: Select all
<?php
if(!$_POST) exit;
$email_field = $_POST['email'];
$name_field = $_POST['name'];
$coupon_field = $_POST['coupon'];
$dog_field = $_POST['dog'];
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email_field )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','coupon','dog');
$required = array('name','email');
$your_email = "advertise@localadsaver.com";
$email_subject = "June Contest Entry: ";
$email_content = "Contest Entry:\n Name: $name_field\n Email: $email_field\n Coupon Name: $coupon_field\n Dog Name: $dog_field\n";
foreach($values as $key => $valuse){
if(in_array($values,$required)){
if ($key != 'dog' && $key != 'coupon') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $values.': '.$_POST[$coupon_field]."\n";
}
}
if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>

