PDA

View Full Version : PHP Email Form checkboxes



carly02
13 Sep 2005, 11:56 AM
I have this php file which shows a form on the page for the user to fill in. It then sends the results to my email. There are some check boxes on there which once checked display in the subject of my email. I would like the result of the checkbox to appear in the message like the rest of the information but cant figure out what to do. The code is attached below.
Thanks for your help
Carly
<?

# Main File. Feedback Mailer. v 1.01

#
# Author: hpnadig
# Last modified on Jan 2004.
#
# copyright 2004, hpnadig. http://hpnadig.com/index.php?pg=scripts
#
# You can use, redistribute the script provided that the author name and credits are maintained
# intact. If you make any changes, I'd be glad if you can inform me about that... and I'll include
# it in the next version of the script with, ofcourse, due credits. So, please do inform me at
# hpnadig@gmail.com,
# along with the diff.
#
# modified by donie
# addition : cookies for form values, website field, easy to integrate with website, and valid XHTML 1.0 trans
#
#################################################################################################### ##

# version 1.01

# CONFIGURATION
# Title of the Page
$title = 'Feedback Mailer v1.0 beta';

# Subject prefix for the mail arriving in your Mail Box... eg. [hpnadig.com-feedback]
$sub = '[Subject-Prefix]';

# The Mail address you want the mail to be sent to...
$address = 'carly@cjpltd.co.uk';

# The Mail address(es) you want to be included in the BCC list...
$ccmail = 'alternative@yourmail.com'; // $ccmail = ''; if you dont want use CC

# The Mail address(es) you want to be included in the BCC list...
$bccmail = 'alternative2@yourmail.com'; // $bccmail = ''; if you dont want use BCC

# Error Messages... edit them to your needs :)
$errors['name'] = "No Name Entered!";
$errors['email'] = "Need proper mail - id";
$errors['website'] = "Need proper website address";
$errors['comments'] = "Please type in your comments!";
$errors['subject'] = "No Subject Selected!";


# error reporting, and misscellany__________________________________________________________ #

# input value cookies
if($submit) {

SetCookie ("namec", $name, time()+2592000);
SetCookie ("emailc", $replyemail, time()+2592000);
SetCookie ("websitec", $website, time()+2592000);
SetCookie ("wherec", $where, time()+2592000);
SetCookie ("findc", $find, time()+2592000);
SetCookie ("commentsc", $comments, time()+2592000);
$namec = $name;
$emailc = $replyemail;
$websitec = $website;
$wherec = $where;
$findc = $find;
$commentsc = $comments;
SetCookie ("namec", $name, time());
SetCookie ("emailc", $replyemail, time());
SetCookie ("websitec", $website, time());
SetCookie ("wherec", $where, time());
SetCookie ("findc", $find, time());
SetCookie ("commentsc", $comments, time());
}

# Error Reporting...
error_reporting(E_NONE);


# Displays the appropriate error message...
function display_error($form_element){

echo " <div align=\"center\" style=\"padding: 0px;\"><b><font color=\"#E96B10\">" .$form_element ."</font></b><br /></div><div align=\"center\" style=\"border-bottom: 1px solid #CCC;\"><br /></div>";

}

# Checks for a valid mail address...
function do_check_email($address) {

return preg_match('/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/',$address);

}

# Checks for a valid website address...
function do_check_website($website) {

return eregi('^([:/~a-zA-Z0-9_\-\.]+)\.([:/~a-zA-Z0-9]+)$',$website);

}

?>

<!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" xml:lang="en" dir="ltr" lang="en">
<head>
<title><?php echo("$title"); ?></title>

<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />

<style type="text/css">

#title {
font-size: 14px; color: #ccc; border-bottom: 1px dashed #efefef; width: 380px; text-decoration: bold;
}

#outerbox {
font-family: verdana, palatino, helvetica, sans-serif, georgia, monospace; background-color:#fafafa; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #dddddd; padding:10px; width: 400px; color: #006699; margin-top:10px;
}

#innerbox {
font-family: verdana, palatino, helvetica, sans-serif, georgia, monospace; width: 380px; border-width: 1px 1px 1px 1px; border-style: solid; border-color: #efefef; background-color:#fafafa; padding:10px; font-size: 11px; color: #006699; line-height: 200%;
}

#innerbox a{
font-family: verdana, palatino, helvetica, sans-serif, georgia, monospace; font-size: 11px; color: #006699;
}

#innerbox a:hover{
font-family: verdana, palatino, helvetica, sans-serif, georgia, monospace;font-size: 11px; color: #dd6900;
}

#form {
font-family: verdana, palatino, helvetica, sans-serif, georgia, monospace; width: 380px; padding:2px; font-size: 11px; color: #006699; line-height: 200%; margin-top: 10px;
}

input,textarea,select{
color : #333;
font: normal 11px palatino, verdana, palatino, sans-serif;;
border: solid; border-width: 1px 1px 1px 1px;
border-color: #efefef;
padding:4px;
background-color:#fff;
}
</style>

</head>

<body>

<div align="center"><div id="title"><?php echo("$title"); ?></div></div>
<div align="center">
<div id="outerbox">
<div id="innerbox">

<?php

// Check for the fields.. yet to be customized.....
if($_POST['done'] == "yes"){
$flag = 1;
if(!($_POST['name']) && $flag){
display_error($errors['name']);
$flag = 0;
}

if(!do_check_email($_POST['replyemail']) && $flag) {
display_error($errors['email']);
$flag = 0;
}

if(!do_check_website($_POST['website']) && $flag) {
display_error($errors['website']);
$flag = 0;
}

if(!($_POST['subject_pre']) && $flag){
display_error($errors['subject']);
$flag = 0;
}

if(!($_POST['comments']) && $flag){
display_error($errors['comments']);
$flag = 0;
}

if ($flag == 1) {
$name = $_POST['name'];
$replyemail = $_POST['replyemail'];
$website = $_POST['website'];
$where = $_POST['where'];
$find = $_POST['find'];

$subject_pre = $_POST['subject_pre'];
$subject = $sub .join(', ', $subject_pre);

$extra_hdr_str = "From: $emailc <$replyemail> \r\ncc: $ccmail \r\nbcc: $bccmail \r\nContent-type: text/html\r\nX-Mailer: PHP/" .phpversion();

$date = strftime('%c (%Z)');

// if there is no 'http://' on website field
if ( substr ($website, 0, 7) != "http://") {
$url = "http://" . $website;
}
else {
$url = $website;
} // done!

$body = "<p align='center'>Date: $date <br /><br /> Name: $name <br /> Email: $replyemail <br /> Website: <a href='$url' target='_blank'>$website</a> <br /><br /> Location: $location <br /> Find: $find <br /><br /> Subject: $Feedback <br /><br /> Message: $comments <br /><br /> IP address: $REMOTE_ADDR</p>";
if($done == "yes")
{
$formsent = mail($address,$subject,$body,$extra_hdr_str); // BUILT IN PHP FUNCTION mail() TO SENT EMAIL

if($formsent) { echo ("<div align=\"center\" style=\"padding: 0px;\"><font color=\"#E96B10\">Thank you very much <b>$name</b> for the feedback!<br /> The Message has been despatched.</font><br /></div><div align=\"center\" style=\"border-bottom: 1px solid #CCC;\"><br /></div>"); }
else { echo ("<div align=\"center\" style=\"padding: 0px;\"><font color=\"#E96B10\">Dear <b>$name</b>, There was a bit of problem - which means, the form <b>hasn't been sent!</b>. Try again... </font><br /></div><div align=\"center\" style=\"border-bottom: 1px solid #CCC;\"><br /></div>"); }
}
}
}
// end of checking
?>

<br />

<?php
if(!$formsent) { // if the email has not been sent, will display message above and form below
?>

<div id="form" align="left">
<form action="<?php echo "$PHP_SELF" ?>" method="post">

<b>Name</b>*<br />
<input class="input" type="text" name="name" size="20" value="<?php echo "$namec"; ?>" /><br />

<b>E-mail</b>*<br />
<input class="input" type="text" name="replyemail" size="20" value="<?php echo "$emailc"; ?>" /><br />

<b>Web Site</b>*<br />
<input class="input" type="text" name="website" size="20" value="<?php echo "$websitec"; ?>" /><br />

<b>Address</b><br />
<textarea name="location" cols="30" rows="8" class="input" id="location"><?php echo "$location"; ?></textarea>
<br />

<b>Where did you hear about Young Group? </b><br />
<textarea name="find" cols="30" rows="8" class="input"><?php echo "$findc"; ?></textarea>
<br />

<b>Select the subject*</b><br />
<input type="checkbox" name="subject_pre[]" value="Feedback" /> Feedback on the Site <br />
<input type="checkbox" name="subject_pre[]" value="Other" /> Other <br />

<b>Comments</b>*<br />
<textarea class="textarea" cols="40" rows="4" name="comments"><?php echo "$commentsc" ?></textarea><br />
* = required<br />
<br />

<div align="center">
<input type="hidden" name="done" value="yes" />
<input class="submit" type="submit" name="submit" value=" Send " />&nbsp;<input class="submit" type="reset" name="cancel" value="Cancel" onclick="location='http://www.yourdomain.com'" /><br />
<br />
<a href="http://www.hpnadig.com/scripts/feedback_mailer/">feedback mailer Beta</a>. &copy; <a href="http://www.hpnadig.com/">hpnadig</a> 2003.
</div>

</form>
</div>

<?php
}// if the email has been sent, will display thank you message above and links below
else {
echo "<a href=\"javascript: history.go(-1)\">back</a>&nbsp;|&nbsp;<a href=\"http://www.yoursite.com\">Home</a><br />";
}
?>

</div></div></div><br />

</body>
</html>

sajjad27s
22 Sep 2005, 07:21 AM
Hello,

Get your code precised so that it might help others to help you.