Forum Moderators: coopster
I have successfully brought them into the form part. But when I send the e-mail I am getting the last name with 'No'. No matter if I checked it or not. Any suggestions?
Here is my code.
this is the part that doesn't work right.
$file = 'people.txt';
$lines = file($file);
foreach ($lines as $value => $line) {
$names = strtok($line, ' ');
//echo "<input type='checkbox' name=\'names[]\' value=\'y\'> $line<br />\n";
//echo "$line<br>";
$names = ($_POST['names'])? "$line: Yes":"$line: No";
//I have tried the following way too. But haven't had any success.
//if ($_POST['names']=='on'){
// echo "{$line}: Yes";
//}
//else {
//echo "{$line}: No";
//}
}
this is the part that does work
$file = 'people.txt';
$lines = file($file);
foreach ($lines as $value => $line) {
$names = strtok($line, ' ');
echo "<input type='checkbox' name=\'names[]\' value=\'{$names}\'> $line<br />\n";
}
Can this be done? or am I just bangin my head against the wall here.
[edited by: dreamcatcher at 6:12 am (utc) on July 11, 2009]
[edit reason] Fixed sidescroll [/edit]
<html>
<form method="post" name ="myForm">
<?php
$file = 'people.txt';
$lines = file($file);
foreach ($lines as $value => $line) {
$line = trim($line);
echo "<input type='checkbox' name='{$line}'> $line<br />\n";
}
?>
<input type = "submit" value = "submit" name ="submit">
</form>
<?php
//now go through all of the names and check
//to see if they are set
if(isset($_POST['submit'])){
$file = 'people.txt';
$lines = file($file);
foreach($lines as $i){
//post variables can't take a space
//so we replace any with an _
$i = trim(str_replace(" ", "_", $i));
if(isset($_POST[$i])){
echo("yes $i<br>");
}//if
else{
echo("no $i<br>");
}
}
}//if isset
?>
</html>
Try that out
<?php
$errmsg = ''; // error message
$line = '';
$email = ''; // sender's email addres
$question = ''; // question one
//now go through all of the names and check
//to see if they are set
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
foreach($lines as $i){
//post variables can't take a space
//so we replace any with an _
$i = trim(str_replace(" ", "_", $i));
if(isset($_POST[$i])){
echo("yes $i<br>");
}//if
else{
echo("no $i<br>");
}
}
//}if isset
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "yourname@company.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
// the mail message ( add any additional information if you want )
$msg = "Names = $i \n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
//$msg .="\n$firstname";
//mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<p><b>Names:</b><br>$i<br></p>";
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
}
if(!isset($_POST['send']) ¦¦ $errmsg != '')
{
//echo 'Could not send';
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Title</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
$file = 'people.txt';
$lines = file($file);
foreach ($lines as $value => $line) {
$names = strtok($line, ' ');
echo "<input type='checkbox' name=\'names[]\' value=\'$names\'> $line<br />\n";
}
?>
</td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text" id="email" size="30">
</td>
</tr>
<!-- <tr>
<td colspan="2" width="106"><h3>Additional Employees</h3></td>
</tr>
<tr>
<td colspan="2" width="500"> <textarea id="question" name="question" rows="10" cols="50" maxlength="2500" class="box" style="font-family:Arial, Helvetica, sans-serif; font-size: 100%;"></textarea></td>
</tr>--></table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]¦[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad¦ae¦aero¦af¦ag¦ai¦al¦am¦an¦ao¦aq¦ar¦arpa¦as¦at¦au¦aw¦az¦ba¦bb¦bd¦ be¦bf¦bg¦bh¦bi¦biz¦bj¦bm¦bn¦bo¦br¦bs¦bt¦bv¦bw¦by¦bz¦ca¦cc¦cd¦cf¦cg¦ch¦ ci¦ck¦cl¦cm¦cn¦co¦com¦coop¦cr¦cs¦cu¦cv¦cx¦cy¦cz¦de¦dj¦dk¦dm¦do¦dz¦ec¦ edu¦ee¦eg¦eh¦er¦es¦et¦eu¦fi¦fj¦fk¦fm¦fo¦fr¦ga¦gb¦gd¦ge¦gf¦gh¦gi¦gl¦gm¦ gn¦gov¦gp¦gq¦gr¦gs¦gt¦gu¦gw¦gy¦hk¦hm¦hn¦hr¦ht¦hu¦id¦ie¦il¦in¦info¦int¦ io¦iq¦ir¦is¦it¦jm¦jo¦jp¦ke¦kg¦kh¦ki¦km¦kn¦kp¦kr¦kw¦ky¦kz¦la¦lb¦lc¦li¦lk¦ lr¦ls¦lt¦lu¦lv¦ly¦ma¦mc¦md¦mg¦mh¦mil¦mk¦ml¦mm¦mn¦mo¦mp¦mq¦mr¦ms¦mt¦mu¦ museum¦mv¦mw¦mx¦my¦mz¦na¦name¦nc¦ne¦net¦nf¦ng¦ni¦nl¦no¦np¦nr¦nt¦nu¦nz¦ om¦org¦pa¦pe¦pf¦pg¦ph¦pk¦pl¦pm¦pn¦pr¦pro¦ps¦pt¦pw¦py¦qa¦re¦ro¦ru¦rw¦sa¦ sb¦sc¦sd¦se¦sg¦sh¦si¦sj¦sk¦sl¦sm¦sn¦so¦sr¦st¦su¦sv¦sy¦sz¦tc¦td¦tf¦tg¦th¦ tj¦tk¦tm¦tn¦to¦tp¦tr¦tt¦tv¦tw¦tz¦ua¦ug¦uk¦um¦us¦uy¦uz¦va¦vc¦ve¦vg¦vi¦vn¦ vu¦wf¦ws¦ye¦yt¦yu¦za¦zm¦zw)$¦(([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5])\.){3}([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5]))$/i"
,$email));
}
?>
[edited by: dreamcatcher at 6:13 am (utc) on July 11, 2009]
[edit reason] Fixed sidescroll [/edit]
<?php
$errmsg = ''; // error message
$line = '';
$email = ''; // sender's email addres
$question = ''; // question one
//now go through all of the names and check
//to see if they are set
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
foreach($lines as $i){
//post variables can't take a space
//so we replace any with an _
$i = trim(str_replace(" ", "_", $i));
if(isset($_POST[$i])){
echo("yes $i<br>");
}//if
else{
echo("no $i<br>");
}
}
//}if isset
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "yourname@company.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
// the mail message ( add any additional information if you want )
$msg = "Names = $i \n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
//$msg .="\n$firstname";
//mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<p><b>Names:</b><br>$i<br></p>";
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
}
if(!isset($_POST['send']) ¦¦ $errmsg != '')
{
//echo 'Could not send';
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Title</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
$file = 'people.txt';
$lines = file($file);
foreach ($lines as $value => $line) {
$line = trim($line);
echo "<input type='checkbox' name='{$line}'> $line<br />\n";
}
?>
</td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text" id="email" size="30">
</td>
</tr>
<!-- <tr>
<td colspan="2" width="106"><h3>Additional Employees</h3></td>
</tr>
<tr>
<td colspan="2" width="500"> <textarea id="question" name="question" rows="10" cols="50" maxlength="2500" class="box" style="font-family:Arial, Helvetica, sans-serif; font-size: 100%;"></textarea></td>
</tr>--></table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
?>
[edited by: dreamcatcher at 6:14 am (utc) on July 11, 2009]
[edit reason] Fixed sidescroll [/edit]
HTML side
----------------------------------------
Jay_Alloway_:No
Richard_Becker_:No
Nancy_Becker_:No
Julie_Bell:No
Thank you for filling out our Constituency Employee form!
Your message has been sent!
Please print the following for your records:
Subject: Results from Academic Services Technology Verification form
Names:
Julie_Bell
E-mail:
shaun.kirmer@gmail.com
Additional Employees:
For your records.
You should also recieve an e-mail with all the information that you just filled out.
If you have any questions please contact foundation@found.ksu.edu.
----------------------------------------
And here is the actual e-mail sent to me.
----------------------------------------
Names = Julie_Bell
E-mail = shaun.kirmer@example.com
Additional Employees =
----------------------------------------
[edited by: dreamcatcher at 6:11 am (utc) on July 11, 2009]
[edit reason] No personal emails, thanks. [/edit]
echo '<pre>'.htmlentities(var_export($_REQUEST, true)).'</pre>';
Having said that, i see in your form processing script you use names with spaces replaced by _s:
$i = trim(str_replace(" ", "_", $i));
Whereas in your form generation script you use "names[]" for field names (your version) or names with embedded spaces (andrewsmd's version):
$line = trim($line);
echo "<input type='checkbox' name='{$line}'> $line<br />\n";
I'd follow andrewsmd's recommendation and use the employee name with embedded _s but you need to use the same logic in both parts. Your best bet is to write a separate function to generate the field name from the employee name and call that in your scripts:
// Returns employee name converted to a value suitable for use as a form field name.
function convertEmployeeNameToFieldName($employeeName) {
return str_replace(' ', '_', trim($employeeName));
}
Then use the same function in both parts of your script:
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
echo("yes $i<br>");
else
echo("no $i<br>");
}
And:
foreach($lines as $employeeName) {
$fieldName = convertEmployeeNameToFieldName($employeeName);
echo "<input type='checkbox' name=\'$fieldName\'> $employeeName<br />\n";
}
Hope this helps... It can never be stressed enough how important it is to break down your code into functions (with descriptive names), especially for logic that is used in multiple places. It'll save you a lot of headaches in the long run. :)
andrewsmd your corrections to my code work like you said it places it into the existing page. But for some reason it doesn't pass on to the e-mail. Check out the following code and see if you can see what I am doing wrong. Maybe I do need to add a function like idfer said. It doesn't seem like it should be a difficult fix. But these small things never do huh!
The current code. Thanks for all your help.
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$errmsg = ''; // error message
$line = '';
$email = ''; // sender's email addres
$question = ''; // question one
//now go through all of the names and check
//to see if they are set
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
foreach($lines as $i){
//post variables can't take a space
//so we replace any with an _
$i = trim(str_replace(" ", "_", $i));
if(isset($_POST[$i])){
echo("yes $i<br>");
}//if
else{
echo("no $i<br>");
}
}
//}if isset
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "yourname@company.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
// the mail message ( add any additional information if you want )
$msg = "Names = $i \n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
//$msg .="\n$firstname";
//mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<p><b>Names:</b><br>$i<br></p>";
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
}
if(!isset($_POST['send']) ¦¦ $errmsg != '')
{
//echo 'Could not send';
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Title</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
$file = 'people.txt';
$lines = file($file);
foreach ($lines as $value => $line) {
$line = trim($line);
echo "<input type='checkbox' name='{$line}'> $line<br />\n";
}
?>
</td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text" id="email" size="30">
</td>
</tr>
<!-- <tr>
<td colspan="2" width="106"><h3>Additional Employees</h3></td>
</tr>
<tr>
<td colspan="2" width="500"> <textarea id="question" name="question" rows="10" cols="50" maxlength="2500" class="box" style="font-family:Arial, Helvetica, sans-serif; font-size: 100%;"></textarea></td>
</tr>--></table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]¦[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad¦ae¦aero¦af¦ag¦ai¦al¦am¦an¦ao¦aq¦ar¦arpa¦as¦at¦au¦aw¦az¦ba¦bb¦bd¦be¦bf¦bg¦bh¦bi¦biz¦bj¦bm¦bn¦bo¦br¦bs¦bt¦bv¦bw¦by¦bz¦ca¦cc¦cd¦cf¦cg¦ch¦ci¦ck¦cl¦cm¦cn¦co¦ com¦coop¦cr¦cs¦cu¦cv¦cx¦cy¦cz¦de¦dj¦dk¦dm¦do¦dz¦ec¦edu¦ee¦eg¦eh¦er¦es¦et¦eu¦ fi¦fj¦fk¦fm¦fo¦fr¦ga¦gb¦gd¦ge¦gf¦gh¦gi¦gl¦gm¦gn¦gov¦gp¦gq¦gr¦gs¦gt¦gu¦gw¦gy¦ hk¦hm¦hn¦hr¦ht¦hu¦id¦ie¦il¦in¦info¦int¦io¦iq¦ir¦is¦it¦jm¦jo¦jp¦ke¦kg¦kh¦ki¦ km¦kn¦kp¦kr¦kw¦ky¦kz¦la¦lb¦lc¦li¦lk¦lr¦ls¦lt¦lu¦lv¦ly¦ma¦mc¦md¦mg¦mh¦mil¦mk ¦ml¦mm¦mn¦mo¦mp¦mq¦mr¦ms¦mt¦mu¦museum¦mv¦mw¦mx¦my¦mz¦na¦name¦nc¦ne¦net¦nf¦ng ¦ni¦nl¦no¦np¦nr¦nt¦nu¦nz¦om¦org¦pa¦pe¦pf¦pg¦ph¦pk¦pl¦pm¦pn¦pr¦pro¦ps¦pt¦pw¦py ¦qa¦re¦ro¦ru¦rw¦sa¦sb¦sc¦sd¦se¦sg¦sh¦si¦sj¦sk¦sl¦sm¦sn¦so¦sr¦st¦su¦sv¦sy¦sz¦tc ¦td¦tf¦tg¦th¦tj¦tk¦tm¦tn¦to¦tp¦tr¦tt¦tv¦tw¦tz¦ua¦ug¦uk¦um¦us¦uy¦uz¦va¦vc¦ve¦vg¦ vi¦vn¦vu¦wf¦ws¦ye¦yt¦yu¦za¦zm¦zw)$¦(([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5])\.){3}([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5]))$/i"
,$email));
}
?>
</body>
</html>
[edited by: dreamcatcher at 6:06 am (utc) on July 11, 2009]
[edit reason] Fixed sidescroll [/edit]
Any Suggestions?
Here is what I have for my existing code.
<?php
$errmsg = ''; // error message
$line = '';
$email = ''; // sender's email addres
$question = ''; // question one
//now go through all of the names and check
//to see if they are set
function convertEmployeeNameToFieldName($employeeName) {
return str_replace(' ', '_', trim($employeeName));
}
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
}
//}if isset
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
//$to = "yourname@company.com";
$to = "shaunk@found.ksu.edu";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
// the mail message ( add any additional information if you want )
//$msg = ;
//if(isset($_POST[$fieldName]))
//echo('$employeeName No<br>');
//else
//echo('$employeeName Yes<br>');
//}
$msg = "\nEmployee Participation: 'if(isset($_POST[$fieldName]))'
//foreach($lines as $employeeName){
//$fieldName = convertEmployeeNameToFieldName($employeeName);
//if(isset($_POST[$fieldName]))
echo('$employeeName No<br>');
else
echo('$employeeName Yes<br>');
}";
//$msg = "$employeeName";
$msg = "\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
//"\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
//$msg .="\n$firstname";
//mail($to, $subject, $msg, "From: $from\r\nReply-To: $from\r\nReturn-Path: $from\r\n");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<b>Employee Participation:</b><br>";
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
echo("$employeeName : No<br>");
else
echo("$employeeName : Yes<br>");
}
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
//}
if(!isset($_POST['send']) ¦¦ $errmsg != '')
{
//echo 'Could not send';
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Title</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
$file = 'people.txt';
$lines = file($file);
foreach($lines as $employeeName) {
$fieldName = convertEmployeeNameToFieldName($employeeName);
echo "<input type='checkbox' name='{$fieldName}'> $employeeName<br />\n";
}
?>
</td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text" id="email" size="30">
</td>
</tr>
<tr>
<td colspan="2" width="106"><h3>Additional Employees</h3></td>
</tr>
<tr>
<td colspan="2" width="500"> <textarea id="question" name="question" rows="10" cols="50" maxlength="2500" class="box" style="font-family:Arial, Helvetica, sans-serif; font-size: 100%;"></textarea></td>
</tr></table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]¦[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad¦ae¦aero¦af¦ag¦ai¦al¦am¦an¦ao¦aq¦ar¦arpa¦as¦at¦au¦aw¦az¦ba¦bb¦bd¦be¦bf¦bg¦bh¦bi¦biz¦bj¦bm¦bn¦bo¦br¦bs¦bt¦bv¦bw¦by¦bz¦ca¦cc¦cd¦cf¦cg¦ch¦ci¦ck¦cl¦cm¦cn¦co¦com¦coop¦cr¦cs¦cu¦cv¦cx¦cy¦cz¦de¦dj¦dk¦dm¦do¦dz¦ec¦edu¦ee¦eg¦eh¦er¦es¦et¦eu¦fi¦fj¦fk¦fm¦fo¦fr¦ga¦gb¦gd¦ge¦gf¦gh¦gi¦gl¦gm¦gn¦gov¦gp¦gq¦gr¦gs¦gt¦gu¦gw¦gy¦hk¦hm¦hn¦hr¦ht¦hu¦id¦ie¦il¦in¦info¦int¦io¦iq¦ir¦is¦it¦jm¦jo¦jp¦ke¦kg¦kh¦ki¦km¦kn¦kp¦kr¦kw¦ky¦kz¦la¦lb¦lc¦li¦lk¦lr¦ls¦lt¦lu¦lv¦ly¦ma¦mc¦md¦mg¦mh¦mil¦mk¦ml¦mm¦mn¦mo¦mp¦mq¦mr¦ms¦mt¦mu¦museum¦mv¦mw¦mx¦my¦mz¦na¦name¦nc¦ne¦net¦nf¦ng¦ni¦nl¦no¦np¦nr¦nt¦nu¦nz¦om¦org¦pa¦pe¦pf¦pg¦ph¦pk¦pl¦pm¦pn¦pr¦pro¦ps¦pt¦pw¦py¦qa¦re¦ro¦ru¦rw¦sa¦sb¦sc¦sd¦se¦sg¦sh¦si¦sj¦sk¦sl¦sm¦sn¦so¦sr¦st¦su¦sv¦sy¦sz¦tc¦td¦tf¦tg¦th¦tj¦tk¦tm¦tn¦to¦tp¦tr¦tt¦tv¦tw¦tz¦ua¦ug¦uk¦um¦us¦uy¦uz¦va¦vc¦ve¦vg¦vi¦vn¦vu¦wf¦ws¦ye¦yt¦yu¦za¦zm¦zw)$¦(([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5])\.){3}([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5]))$/i"
,$email));
}
?>
[edited by: dreamcatcher at 6:17 am (utc) on July 23, 2009]
[edit reason] Fixed sidescroll [/edit]
I tried sending the $mail variable both ways each does send. I guess I should have clarified. The part that it doesn't send in to the e-mail is the $msg variable. This is the part that the names are involved with. I get the $email and $question variables to send what is in there fields.
I placed $employeeName, and $fieldName into the $msg and get nothing in return. I think I need to incorporate the foreach statement but not sure how to make $msg pick up the names and there selected state.
Does that make sense?
Thanks again for the help.
I would like the names to come back with either yes or no. Not sure if in the text area you mean the actual field? The form right now sends anything back that I type in there.
Thanks for your help.
<?php
$errmsg = ''; // error message
$line = '';
$email = ''; // sender's email addres
$question = ''; // question one
function convertEmployeeNameToFieldName($employeeName) {
return str_replace(' ', '_', trim($employeeName));
}
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
}
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "yourname@company.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
$msg = " \n".stripslashes($_POST[$fieldName])."\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<b>Employee Participation:</b><br>";
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
echo("$employeeName : No<br>");
else
echo("$employeeName : Yes<br>");
}
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
?>
<div><h3>For your records.</h3> <p>You should also recieve an e-mail with all the information that you just filled out.</p>
</div>
<?php
}
//}
if(!isset($_POST['send']) ¦¦ $errmsg != '')
{
//echo 'Could not send';
?>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style:normal; text-align: left;"><h3>Title</h3></div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
$file = 'people.txt';
$lines = file($file);
foreach($lines as $employeeName) {
$fieldName = convertEmployeeNameToFieldName($employeeName);
echo "<input type='checkbox' name='{$fieldName}'> $employeeName<br />\n";
}
?>
</td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text" id="email" size="30">
</td>
</tr>
<tr>
<td colspan="2" width="106"><h3>Additional Employees</h3></td>
</tr>
<tr>
<td colspan="2" width="500"> <textarea id="question" name="question" rows="10" cols="50" maxlength="2500" class="box" style="font-family:Arial, Helvetica, sans-serif; font-size: 80%;"></textarea></td>
</tr></table>
<input name="send" type="submit" id="send" value="Send it">
<!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset"/>
</form>
<?php
}
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]¦[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad¦ae¦aero¦af¦ag¦ai¦al¦am¦an¦ao¦aq¦ar¦arpa¦as¦at¦au¦aw¦az¦ba¦bb¦bd¦be¦bf¦bg¦bh¦bi¦biz¦bj¦bm¦bn¦bo¦br¦bs¦bt¦bv¦bw¦by¦bz¦ca¦cc¦cd¦cf¦cg¦ch¦ci¦ck¦cl¦cm¦cn¦co¦com¦coop¦cr¦cs¦cu¦cv¦cx¦cy¦cz¦de¦dj¦dk¦dm¦do¦dz¦ec¦edu¦ee¦eg¦eh¦er¦es¦et¦eu¦fi¦fj¦fk¦fm¦fo¦fr¦ga¦gb¦gd¦ge¦gf¦gh¦gi¦gl¦gm¦gn¦gov¦gp¦gq¦gr¦gs¦gt¦gu¦gw¦gy¦hk¦hm¦hn¦hr¦ht¦hu¦id¦ie¦il¦in¦info¦int¦io¦iq¦ir¦is¦it¦jm¦jo¦jp¦ke¦kg¦kh¦ki¦km¦kn¦kp¦kr¦kw¦ky¦kz¦la¦lb¦lc¦li¦lk¦lr¦ls¦lt¦lu¦lv¦ly¦ma¦mc¦md¦mg¦mh¦mil¦mk¦ml¦mm¦mn¦mo¦mp¦mq¦mr¦ms¦mt¦mu¦museum¦mv¦mw¦mx¦my¦mz¦na¦name¦nc¦ne¦net¦nf¦ng¦ni¦nl¦no¦np¦nr¦nt¦nu¦nz¦om¦org¦pa¦pe¦pf¦pg¦ph¦pk¦pl¦pm¦pn¦pr¦pro¦ps¦pt¦pw¦py¦qa¦re¦ro¦ru¦rw¦sa¦sb¦sc¦sd¦se¦sg¦sh¦si¦sj¦sk¦sl¦sm¦sn¦so¦sr¦st¦su¦sv¦sy¦sz¦tc¦td¦tf¦tg¦th¦tj¦tk¦tm¦tn¦to¦tp¦tr¦tt¦tv¦tw¦tz¦ua¦ug¦uk¦um¦us¦uy¦uz¦va¦vc¦ve¦vg¦vi¦vn¦vu¦wf¦ws¦ye¦yt¦yu¦za¦zm¦zw)$¦(([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5])\.){3}([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5]))$/i"
,$email));
}
?>
[edited by: dreamcatcher at 6:16 am (utc) on July 23, 2009]
[edit reason] Fixed sidescroll [/edit]
<html>
<div>
<h3>For your records.</h3>
<p>You should also recieve an e-mail with all the information that you
just filled out.</p>
</div>
<div align="left" class="errmsg"><?=$errmsg;?></div>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style: normal; text-align: left;">
<h3>Title</h3>
</div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top"><?php
$file = 'people.txt';
$lines = file($file);
foreach($lines as $employeeName) {
$fieldName = convertEmployeeNameToFieldName($employeeName);
echo "<input type='checkbox' name='{$fieldName}'> $employeeName<br />\n";
}
?></td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text"
id="email" size="30"></td>
</tr>
<tr>
<td colspan="2" width="106">
<h3>Additional Employees</h3>
</td>
</tr>
<tr>
<td colspan="2" width="500"><textarea id="question" name="question"
rows="10" cols="50" maxlength="2500" class="box"
style="font-family: Arial, Helvetica, sans-serif; font-size: 80%;"></textarea></td>
</tr>
</table>
<input name="send" type="submit" id="send" value="Send it"> <!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset" /></form>
<?php
$errmsg = ''; // error message
$line = '';
$email = ''; // sender's email addres
$question = ''; // question one
function convertEmployeeNameToFieldName($employeeName) {
return str_replace(' ', '_', trim($employeeName));
}
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$question = stripslashes($question);
}
// the email will be sent here
$to = "yourname@company.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
$msg = " \n".stripslashes($_POST[$fieldName])."\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
var_dump(" \n".stripslashes($_POST[$fieldName])."\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ");
//$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<b>Employee Participation:</b><br>";
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
echo("$employeeName : No<br>");
else
echo("$employeeName : Yes<br>");
}
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
} else {
echo "There was an error...";
}
}
}//if isset
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]¦[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad¦ae¦aero¦af¦ag¦ai¦al¦am¦an¦ao¦aq¦ar¦arpa¦as¦at¦au¦aw¦az¦ba¦bb¦bd¦be¦bf¦bg¦bh¦bi¦biz¦bj¦bm¦bn¦bo¦br¦bs¦bt¦bv¦bw¦by¦bz¦ca¦cc¦cd¦cf¦cg¦ch¦ci¦ck¦cl¦cm¦cn¦co¦com¦coop¦cr¦cs¦cu¦cv¦cx¦cy¦cz¦de¦dj¦dk¦dm¦do¦dz¦ec¦edu¦ee¦eg¦eh¦er¦es¦et¦eu¦fi¦fj¦fk¦fm¦fo¦fr¦ga¦gb¦gd¦ge¦gf¦gh¦gi¦gl¦gm¦gn¦gov¦gp¦gq¦gr¦gs¦gt¦gu¦gw¦gy¦hk¦hm¦hn¦hr¦ht¦hu¦id¦ie¦il¦in¦info¦int¦io¦iq¦ir¦is¦it¦jm¦jo¦jp¦ke¦kg¦kh¦ki¦km¦kn¦kp¦kr¦kw¦ky¦kz¦la¦lb¦lc¦li¦lk¦lr¦ls¦lt¦lu¦lv¦ly¦ma¦mc¦md¦mg¦mh¦mil¦mk¦ml¦mm¦mn¦mo¦mp¦mq¦mr¦ms¦mt¦mu¦museum¦mv¦mw¦mx¦my¦mz¦na¦name¦nc¦ne¦net¦nf¦ng¦ni¦nl¦no¦np¦nr¦nt¦nu¦nz¦om¦org¦pa¦pe¦pf¦pg¦ph¦pk¦pl¦pm¦pn¦pr¦pro¦ps¦pt¦pw¦py¦qa¦re¦ro¦ru¦rw¦sa¦sb¦sc¦sd¦se¦sg¦sh¦si¦sj¦sk¦sl¦sm¦sn¦so¦sr¦st¦su¦sv¦sy¦sz¦tc¦td¦tf¦tg¦th¦tj¦tk¦tm¦tn¦to¦tp¦tr¦tt¦tv¦tw¦tz¦ua¦ug¦uk¦um¦us¦uy¦uz¦va¦vc¦ve¦vg¦vi¦vn¦vu¦wf¦ws¦ye¦yt¦yu¦za¦zm¦zw)$¦(([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5])\.){3}([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5]))$/i"
,$email));
}
?>
</html>
[edited by: dreamcatcher at 6:20 am (utc) on July 23, 2009]
[edit reason] Fixed sidescroll [/edit]
On my original code after the form was filled out and sent it was replaced by the echo statements Saying thank you. Is that possible to get back. Sorry to be such a pain.
Not sure why but instead of getting even the last name in the list like I used to I get a 1 in return to the email.
I saw that andrewsmd used a var_dump. I think in the code below I messed around with var_export. Still get the same results. Not sure which is better to use for this project? On screen when you send the form after filling it out it states
" Employee Participation = E-mail = yourname@email.com Additional Employees = ".
But it skips adding in the Employee Participation (the list of names). That is where either var_dump or var_export should come into to play. Correct?
Not sure if I have that portion of the code set up correctly to pass on this info into the e-mail. Any suggestions?
Here is my code:
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style: normal; text-align: left;">
<h3>Title</h3>
</div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top">
<?php
$file = 'people.txt';
$lines = file($file);foreach($lines as $employeeName) {
$fieldName = convertEmployeeNameToFieldName($employeeName);
echo "<input type='checkbox' name='{$fieldName}'> $employeeName<br />\n";
}
?>
</td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text"
id="email" size="30"></td>
</tr>
<tr>
<td colspan="2" width="106">
<h3>Additional Employees</h3>
</td>
</tr>
<tr>
<td colspan="2" width="500"><textarea id="question" name="question"
rows="10" cols="50" maxlength="2500" class="box"
style="font-family: Arial, Helvetica, sans-serif; font-size: 80%;"></textarea></td>
</tr>
</table>
<input name="send" type="submit" id="send" value="Send it"> <!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset" />
</form>
<?php
$errmsg = ''; // error message
$lines = '';
$email = ''; // sender's email addres
$question = ''; // question one
function convertEmployeeNameToFieldName($employeeName) {
return str_replace(' ', '_', trim($employeeName));
}
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$email = stripslashes($email);
}
// no errors, so we build our message
// the email will be sent here
$to = "yourname@email.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
//$msg = " \nEmployee Participation = $fieldName \n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
$msg = " \nEmployee Participation = ".stripslashes(isset($_POST[$fieldName]))."\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
var_export(" \nEmployee Participation = ".stripslashes(isset($_POST[$fieldName]))."\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ");
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if (mailsent) {
//if (mail("$to, $email", $subject, $msg, $headers)){
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>For your records.</h3>";
echo "<p>You should also recieve an e-mail with all the information that you just filled out.</p>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<b>Employee Participation:</b><br>";
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
echo("$employeeName : No<br>");
else
echo("$employeeName : Yes<br>");
}
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
}
else {
echo "There was an error...";
}
}
}//if isset
function isEmail($email)
{
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]¦[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad¦ae¦aero¦af¦ag¦ai¦al¦am¦an¦ao¦aq¦ar¦arpa¦as¦at¦au¦aw¦az¦ba¦bb¦bd¦be¦bf¦bg¦bh¦bi¦biz¦bj¦bm¦bn¦bo¦br¦bs¦bt¦bv¦bw¦by¦bz¦ca¦cc¦cd¦cf¦cg¦ch¦ci¦ck¦cl¦cm¦cn¦co¦com¦coop¦cr¦cs¦cu¦cv¦cx¦cy¦cz¦de¦dj¦dk¦dm¦do¦dz¦ec¦edu¦ee¦eg¦eh¦er¦es¦et¦eu¦fi¦fj¦fk¦fm¦fo¦fr¦ga¦gb¦gd¦ge¦gf¦gh¦gi¦gl¦gm¦gn¦gov¦gp¦gq¦gr¦gs¦gt¦gu¦gw¦gy¦hk¦hm¦hn¦hr¦ht¦hu¦id¦ie¦il¦in¦info¦int¦io¦iq¦ir¦is¦it¦jm¦jo¦jp¦ke¦kg¦kh¦ki¦km¦kn¦kp¦kr¦kw¦ky¦kz¦la¦lb¦lc¦li¦lk¦lr¦ls¦lt¦lu¦lv¦ly¦ma¦mc¦md¦mg¦mh¦mil¦mk¦ml¦mm¦mn¦mo¦mp¦mq¦mr¦ms¦mt¦mu¦museum¦mv¦mw¦mx¦my¦mz¦na¦name¦nc¦ne¦net¦nf¦ng¦ni¦nl¦no¦np¦nr¦nt¦nu¦nz¦om¦org¦pa¦pe¦pf¦pg¦ph¦pk¦pl¦pm¦pn¦pr¦pro¦ps¦pt¦pw¦py¦qa¦re¦ro¦ru¦rw¦sa¦sb¦sc¦sd¦se¦sg¦sh¦si¦sj¦sk¦sl¦sm¦sn¦so¦sr¦st¦su¦sv¦sy¦sz¦tc¦td¦tf¦tg¦th¦tj¦tk¦tm¦tn¦to¦tp¦tr¦tt¦tv¦tw¦tz¦ua¦ug¦uk¦um¦us¦uy¦uz¦va¦vc¦ve¦vg¦vi¦vn¦vu¦wf¦ws¦ye¦yt¦yu¦za¦zm¦zw)$¦(([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5])\.){3}([0-9][0-9]?¦[0-1][0-9][0-9]¦[2][0-4][0-9]¦[2][5][0-5]))$/i"
,$email));
}
?>
<html>
<body>
<form id="msgform" name="msgform" method="post">
<table id="ValidCheckbox4" width="620">
<caption>
<div style="font-style: normal; text-align: left;">
<h3>Title</h3>
</div>
</caption>
<tbody>
</tbody>
<tr>
<td valign="top"><?php
$file = 'people.txt';
$lines = file($file);
foreach($lines as $employeeName) {
$fieldName = convertEmployeeNameToFieldName($employeeName);
echo "<input type='checkbox' name='{$fieldName}'> $employeeName<br />\n";
}
?></td>
</tr>
<tr id="email">
<td><label for="Email">Email</label> <input name="email" type="text"
id="email" size="30"></td>
</tr>
<tr>
<td colspan="2" width="106">
<h3>Additional Employees</h3>
</td>
</tr>
<tr>
<td colspan="2" width="500"><textarea id="question" name="question"
rows="10" cols="50" maxlength="2500" class="box"
style="font-family: Arial, Helvetica, sans-serif; font-size: 80%;"></textarea></td>
</tr>
</table>
<input name="send" type="submit" id="send" value="Send it"> <!--<input type="submit" value="Send it"/>-->
<input type="reset" value="Reset" /></form>
<?php
$errmsg = ''; // error message
$lines = '';
$email = ''; // sender's email addres
$question = ''; // question one
function convertEmployeeNameToFieldName($employeeName) {
return str_replace(' ', '_', trim($employeeName));
}
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
$email = $_POST['email'];
$question = $_POST['question'];
$subject = 'Constituency Employee Verification';
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers = "Content-Transfer-Encoding: 7bit\r\n";
$headers = "From: $email\r\n";
if(trim($email) == '')
{
$errmsg = 'Please enter your email address';
}
else if(!isEmail($email))
{
$errmsg = 'Your email address is not valid';
}
if($errmsg == '')
{
if(get_magic_quotes_gpc())
{
$email = stripslashes($email);
}
// no errors, so we build our message
// the email will be sent here
$to = "yourname@email.com";
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
$msg = "\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if ($mailsent) {
//if (mail("$to, $email", $subject, $msg, $headers)){
echo "<h2>Thank you for filling out our Verification form!</h2>";
echo "<h3>For your records.</h3>";
echo "<p>You should also recieve an e-mail with all the information that you just filled out.</p>";
echo "<h3>Your message has been sent!</h3>";
echo "<p>Please print the following for your records:</p>";
echo "<p><b>Subject:</b> $subject</p>";
echo "<b>Employee Participation:</b><br>";
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
echo("$employeeName : Yes<br>");
else
echo("$employeeName : no<br>");
}
echo "<p><b>E-mail:</b><br>$email</p>";
echo "<p><b>Additional Employees:</b><br>";
echo "$question</p>";
}
else {
echo "There was an error...";
}
}
//
}//if isset
function isEmail($email)
{
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}//isEmail
?>
</body>
</html>
way simpler than how I wrote it! That is awesome. Thanks a bunch.
So the output is working correctly. Is there a way for me to bring in the names to the mailsent area? Right now it still skips that part when you receive an e-mail from the form.
// the email subject ( modify it as you wish )
$subject = 'Verification form' ;
$msg = "\n\n\nE-mail = $email \n\nAdditional Employees = $question \n\n ";
foreach($lines as $employeeName){
$fieldName = convertEmployeeNameToFieldName($employeeName);
if(isset($_POST[$fieldName]))
$msg .= ("$employeeName : Yes\n");
else
$msg.=("$employeeName : No\n");
}//foreach
$mailsent = mail("$to,$email", $subject, $msg, $headers);
if ($mailsent) {