Forum Moderators: coopster

Message Too Old, No Replies

Problem populating an external DB into an e-mail

sending unknown number of checkboxes to e-mail

         

shaunk

8:46 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



I am trying to send an unknown number of 'peoples names' to a form as checkboxes and then when they are checked pass along the name with either a 'Yes' or a 'No'.

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]

andrewsmd

2:30 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What does people.txt look like. I've worked a lot with reading files so I may be able to help, I just need some sample text.

shaunk

2:40 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



Right now it is just the following list of random names.

Jay Alloway
Richard Becker
Nancy Becker
Julie Bell

andrewsmd

2:45 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could be having problems with white spaces because php will automatically add an _ for white spaces. I got this to work
people.txt
Jane Doe
John Smith
Bill Brasky

<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

shaunk

3:10 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



First off thanks for your help. I have been racking my brain. I still get the same outcome with the new code. So here is my whole code maybe you can tell me where my error is. I am sure you have it correct. But there has to be something that I have wrong.

<?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]

shaunk

3:15 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



I forgot to add in your code to the form line. But when I did that it gave me the same outcome.

andrewsmd

3:29 pm on Jul 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must have had a typo try this. It's all of your 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

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']) &#166;&#166; $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]

shaunk

3:46 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



So where the $msg and $mailsent areas are it only gives me back the last name on the list. I have right now $i as the variable that is suppose to be displayed but the form is acting like that doesn't see any of the trim code you sent me?

shaunk

3:51 pm on Jul 9, 2009 (gmt 0)

10+ Year Member



Here is what I am getting in return. I just noticed it didn't add yes to the names I had clicked either. Sorry not trying to be a pain. I really do appreciate the help.

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]

idfer

5:31 pm on Jul 10, 2009 (gmt 0)

10+ Year Member



Hi shaunk, it looks like the two parts of your application disagree on the field names. There are two tools that can help you debug this. Either in your browser, do a view source of the form page and look at the name attributes of your <input> fields. Or in the PHP script, add this to the beginning of your script to echo back all the form values sent to your script:

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

6:00 pm on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not for sure I see what your problem is. I don't see a $msg variable. Also, my code works, if you are trying to insert it into an existing page, post the whole page and I can fix it for you.

shaunk

3:18 am on Jul 11, 2009 (gmt 0)

10+ Year Member



Thanks for the help idfer and andrewsmd. I really appreciate it. I think I bit off a little more than I can chew with this one. I am still learning. But all your help is really teaching me some new things.

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]

shaunk

4:05 pm on Jul 20, 2009 (gmt 0)

10+ Year Member



I almost have the problem fixed.
What I am running into right now it I am not sure how to get the results sent through an e-mail.

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]

andrewsmd

4:54 pm on Jul 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your mail function your are saying
mail("$to,$email", ...)
I am not for sure if you can send to more than one recipient in that way. Just write the mail function twice
mail($to, ...);
mail($email, ...);
Also, are you running this PHP on a windows box? Windows does not inherently have the mail function. You will need to download it if you are on a windows based php server. Hope that helps.

shaunk

6:17 pm on Jul 20, 2009 (gmt 0)

10+ Year Member



Thanks for the tip.

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.

shaunk

8:58 pm on Jul 21, 2009 (gmt 0)

10+ Year Member



I have tried a couple more things with no real results. In $msg I tried to make it retrieve $fieldName and only got the last name in the people file. With no YES or NO. I then tried to call $lines and get it to say array back to me. Does anyone have any ideas?

andrewsmd

9:13 pm on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've got a lot of code here and it's kind of difficult for me to edit it.
Could you please just post the relevant parts?
I am having trouble adding all of that into a file quickly.
Also, so you want to email all of the names they check?
Or do you want to email all of the names with either yes or no.
In addition, what do you want to do with the names in the text area?
Please get back to me and I'll give you some help.

shaunk

9:28 pm on Jul 21, 2009 (gmt 0)

10+ Year Member



Here is the current code. I have been commenting things out that don't work. But here is a cleaned up version.

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]

andrewsmd

10:09 pm on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I noticed a couple things. You need to have all of your code in the if isset. That executes on the send button click and right now you are only doing
if(isset($_POST['send'])){
$file = 'people.txt';
$lines = file($file);
}
Which is assigning file and lines and then nothing else happens. Everything else is trying to happen on the page load because it is just in php tags. I have cleaned up your code for you so it's much easier to read. Also, I can tell that if($errmsg == '') is always returning false. Work on that some and I'll help you more tomorrow.

<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:]]&#166;[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad&#166;ae&#166;aero&#166;af&#166;ag&#166;ai&#166;al&#166;am&#166;an&#166;ao&#166;aq&#166;ar&#166;arpa&#166;as&#166;at&#166;au&#166;aw&#166;az&#166;ba&#166;bb&#166;bd&#166;be&#166;bf&#166;bg&#166;bh&#166;bi&#166;biz&#166;bj&#166;bm&#166;bn&#166;bo&#166;br&#166;bs&#166;bt&#166;bv&#166;bw&#166;by&#166;bz&#166;ca&#166;cc&#166;cd&#166;cf&#166;cg&#166;ch&#166;ci&#166;ck&#166;cl&#166;cm&#166;cn&#166;co&#166;com&#166;coop&#166;cr&#166;cs&#166;cu&#166;cv&#166;cx&#166;cy&#166;cz&#166;de&#166;dj&#166;dk&#166;dm&#166;do&#166;dz&#166;ec&#166;edu&#166;ee&#166;eg&#166;eh&#166;er&#166;es&#166;et&#166;eu&#166;fi&#166;fj&#166;fk&#166;fm&#166;fo&#166;fr&#166;ga&#166;gb&#166;gd&#166;ge&#166;gf&#166;gh&#166;gi&#166;gl&#166;gm&#166;gn&#166;gov&#166;gp&#166;gq&#166;gr&#166;gs&#166;gt&#166;gu&#166;gw&#166;gy&#166;hk&#166;hm&#166;hn&#166;hr&#166;ht&#166;hu&#166;id&#166;ie&#166;il&#166;in&#166;info&#166;int&#166;io&#166;iq&#166;ir&#166;is&#166;it&#166;jm&#166;jo&#166;jp&#166;ke&#166;kg&#166;kh&#166;ki&#166;km&#166;kn&#166;kp&#166;kr&#166;kw&#166;ky&#166;kz&#166;la&#166;lb&#166;lc&#166;li&#166;lk&#166;lr&#166;ls&#166;lt&#166;lu&#166;lv&#166;ly&#166;ma&#166;mc&#166;md&#166;mg&#166;mh&#166;mil&#166;mk&#166;ml&#166;mm&#166;mn&#166;mo&#166;mp&#166;mq&#166;mr&#166;ms&#166;mt&#166;mu&#166;museum&#166;mv&#166;mw&#166;mx&#166;my&#166;mz&#166;na&#166;name&#166;nc&#166;ne&#166;net&#166;nf&#166;ng&#166;ni&#166;nl&#166;no&#166;np&#166;nr&#166;nt&#166;nu&#166;nz&#166;om&#166;org&#166;pa&#166;pe&#166;pf&#166;pg&#166;ph&#166;pk&#166;pl&#166;pm&#166;pn&#166;pr&#166;pro&#166;ps&#166;pt&#166;pw&#166;py&#166;qa&#166;re&#166;ro&#166;ru&#166;rw&#166;sa&#166;sb&#166;sc&#166;sd&#166;se&#166;sg&#166;sh&#166;si&#166;sj&#166;sk&#166;sl&#166;sm&#166;sn&#166;so&#166;sr&#166;st&#166;su&#166;sv&#166;sy&#166;sz&#166;tc&#166;td&#166;tf&#166;tg&#166;th&#166;tj&#166;tk&#166;tm&#166;tn&#166;to&#166;tp&#166;tr&#166;tt&#166;tv&#166;tw&#166;tz&#166;ua&#166;ug&#166;uk&#166;um&#166;us&#166;uy&#166;uz&#166;va&#166;vc&#166;ve&#166;vg&#166;vi&#166;vn&#166;vu&#166;wf&#166;ws&#166;ye&#166;yt&#166;yu&#166;za&#166;zm&#166;zw)$&#166;(([0-9][0-9]?&#166;[0-1][0-9][0-9]&#166;[2][0-4][0-9]&#166;[2][5][0-5])\.){3}([0-9][0-9]?&#166;[0-1][0-9][0-9]&#166;[2][0-4][0-9]&#166;[2][5][0-5]))$/i"
,$email));
}

?>
</html>

[edited by: dreamcatcher at 6:20 am (utc) on July 23, 2009]
[edit reason] Fixed sidescroll [/edit]

shaunk

8:36 pm on Jul 22, 2009 (gmt 0)

10+ Year Member



I totally agree that it is easier to read. But I am still getting the same results kind of. I get a 1 to come back instead of the list of peoples names and the yes or no that can be selected.

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.

andrewsmd

8:54 pm on Jul 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't delete any code, just rearranged it. Please post what you have now and I'll take a look at it.

shaunk

1:51 pm on Jul 23, 2009 (gmt 0)

10+ Year Member



Here is what I am wrestling with so far.

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));
}

?>

andrewsmd

2:23 pm on Jul 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alright I found your problem. Your check email regex is always returning false, even when I put in a valid email. I don't know if you wrote it or where you got it, but it's horribly overcomplicated anyways. Try this code. Note, I didn't test the mail sent but I got the output to echo the way you want it to.

<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>

shaunk

2:37 pm on Jul 23, 2009 (gmt 0)

10+ Year Member



Wow you really made that
(return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);)

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.

andrewsmd

3:05 pm on Jul 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's because you send the mail and check to see if that works and then print the output. Just add another for loop here.
// 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 ";

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) {

shaunk

3:12 pm on Jul 23, 2009 (gmt 0)

10+ Year Member



OOOOK! Thanks for all your help.

I guess I tried that earlier but that was before everything was in isset($_POST). So it wouldn't return things.

Now all is well and I get my list too. Thanks so much for your patience with me. I still have a lot to learn.

andrewsmd

3:29 pm on Jul 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem, we were all there once.