chrisnpg
01-21-2009, 12:23 AM
All the data that I have on my form is working, as name, address, and so on. But I have two checkboxes on the form that I need to get to work. They are simple, if checked then I want it to ad that info in the email sent. Although it would be nice that if not checked to process it into the email that it was not checked.
Here is my code that I have on the form:
<form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:580px;" onsubmit="MM_validateForm('from','','RisEmail','subject','', 'R','verif_box','','R','message','','R');return document.MM_returnValue">
Your e-mail:<br />
<input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['from'];?>"/>
<br />
<br />
Subject:<br />
<input name="subject" type="text" id="subject" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['subject'];?>"/>
<br />
<br />
Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/>
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
<br />
<!-- if the variable "wrong_code" is sent from previous page then display the error field -->
<?php if(isset($_GET['wrong_code'])){?>
<div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code</div>
<p><br />
<?php ;}?>
Full Name:<br />
<input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['name'];?>"/>
<br />
<br />
Your Address:<br />
<input name="address" type="text" id="address" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['address'];?>"/>
<br />
<br />
City:<br />
<input name="city" type="text" id="city" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['city'];?>"/>
<br />
<br />
State:<br />
<input name="state" type="text" id="state" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['state'];?>"/>
<br />
<br />
Zip/Postal Code:<br />
<input name="zipcode" type="text" id="zipcode" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['zipcode'];?>"/>
<br />
<br />
Message:<br />
<textarea name="message" cols="6" rows="5" id="message" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"><?php echo $_GET['message'];?></textarea>
<br />
<p><INPUT TYPE="checkbox" id="yessnailmail" VALUE="<?php echo $_GET['yessnailmail'];?>"/>
<B>Yes Send promotional offers, materials, newsletters from CCE Inc via
snail mail</B> <br />
<br />
<INPUT TYPE="checkbox" id="yesemail" VALUE="<?php echo $_GET['yesemail'];?>"/>
<B>Yes Send emails from CCE about upcoming events and promotions</B>
<br />
<br />
<input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;" value="Send Message"/>
</p>
</form>
Here is the mailer.php file:
// remember to replace you@email.com with your own email address lower in this code.
// load the variables form address bar
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$verif_box = $_REQUEST["verif_box"];
$name = $_REQUEST["name"];
$address = $_REQUEST["address"];
$city = $_REQUEST["city"];
$state = $_REQUEST["state"];
$zipcode = $_REQUEST["zipcode"];
$yessnailmail = $_REQUEST["yessnailmail"];
$yesemail = $_REQUEST["yesemail"];
// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
$message = $zipcode . "\n\n" . $message;
$message = $state . "\n" . $message;
$message = $city . "\n" . $message;
$message = $address . "\n" . $message;
$message = $name . "\n" . $message;
'Yes please send mailings: ' .$message = $yessnailmail . "\n" . $message;
$message = $yesemail . "\n" . $message;
mail("myemail@gmail.com", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n\n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else {
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>E-Mail Sent</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style></head>
<body>
Email sent. Thank you.<br />
<br />
Return to <a href="/">home page</a> ?
</body>
</html>
I am new to php, I think I need to ad some if functions to the code. Something to show in the email that yes they want mailings and yes they want emails sent to them. So above is as far as I have gotten and have been stuck. Any tips please!!
Thank you.
Here is my code that I have on the form:
<form action="mailer.php" method="post" name="form1" id="form1" style="margin:0px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px; width:580px;" onsubmit="MM_validateForm('from','','RisEmail','subject','', 'R','verif_box','','R','message','','R');return document.MM_returnValue">
Your e-mail:<br />
<input name="from" type="text" id="from" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px; font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;" value="<?php echo $_GET['from'];?>"/>
<br />
<br />
Subject:<br />
<input name="subject" type="text" id="subject" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['subject'];?>"/>
<br />
<br />
Type verification image:<br />
<input name="verif_box" type="text" id="verif_box" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"/>
<img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" align="absbottom" /><br />
<br />
<!-- if the variable "wrong_code" is sent from previous page then display the error field -->
<?php if(isset($_GET['wrong_code'])){?>
<div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code</div>
<p><br />
<?php ;}?>
Full Name:<br />
<input name="name" type="text" id="name" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['name'];?>"/>
<br />
<br />
Your Address:<br />
<input name="address" type="text" id="address" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['address'];?>"/>
<br />
<br />
City:<br />
<input name="city" type="text" id="city" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['city'];?>"/>
<br />
<br />
State:<br />
<input name="state" type="text" id="state" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['state'];?>"/>
<br />
<br />
Zip/Postal Code:<br />
<input name="zipcode" type="text" id="zipcode" style="padding:2px; border:1px solid #CCCCCC; width:190px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;" value="<?php echo $_GET['zipcode'];?>"/>
<br />
<br />
Message:<br />
<textarea name="message" cols="6" rows="5" id="message" style="padding:2px; border:1px solid #CCCCCC; width:300px; height:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px;"><?php echo $_GET['message'];?></textarea>
<br />
<p><INPUT TYPE="checkbox" id="yessnailmail" VALUE="<?php echo $_GET['yessnailmail'];?>"/>
<B>Yes Send promotional offers, materials, newsletters from CCE Inc via
snail mail</B> <br />
<br />
<INPUT TYPE="checkbox" id="yesemail" VALUE="<?php echo $_GET['yesemail'];?>"/>
<B>Yes Send emails from CCE about upcoming events and promotions</B>
<br />
<br />
<input name="Submit" type="submit" style="margin-top:10px; display:block; border:1px solid #000000; width:100px; height:20px;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px; padding-left:2px; padding-right:2px; padding-top:0px; padding-bottom:2px; line-height:14px; background-color:#EFEFEF;" value="Send Message"/>
</p>
</form>
Here is the mailer.php file:
// remember to replace you@email.com with your own email address lower in this code.
// load the variables form address bar
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$verif_box = $_REQUEST["verif_box"];
$name = $_REQUEST["name"];
$address = $_REQUEST["address"];
$city = $_REQUEST["city"];
$state = $_REQUEST["state"];
$zipcode = $_REQUEST["zipcode"];
$yessnailmail = $_REQUEST["yessnailmail"];
$yesemail = $_REQUEST["yesemail"];
// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
$message = $zipcode . "\n\n" . $message;
$message = $state . "\n" . $message;
$message = $city . "\n" . $message;
$message = $address . "\n" . $message;
$message = $name . "\n" . $message;
'Yes please send mailings: ' .$message = $yessnailmail . "\n" . $message;
$message = $yesemail . "\n" . $message;
mail("myemail@gmail.com", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n\n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else {
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>E-Mail Sent</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
-->
</style></head>
<body>
Email sent. Thank you.<br />
<br />
Return to <a href="/">home page</a> ?
</body>
</html>
I am new to php, I think I need to ad some if functions to the code. Something to show in the email that yes they want mailings and yes they want emails sent to them. So above is as far as I have gotten and have been stuck. Any tips please!!
Thank you.