Let me start by apologizing ahead of time for my complete and utter lack of knowledge with respect to PHP coding.
I've been tasked with creating a timesheet that office employees would fill out at the end of each day for time tracking purposes. This form would then be sent electronically to be input into our accounting software.
The form is as follows:
I've used a little javascript to validate the form to ensure certain fields have been entered correctly. If everything checks out, the PHP script is supposed to kick in and email the contents (of only filled in fields) to the desired address.
My goal here is to to have the end message looks something like this:
...but, if fields are blank, I would like to have them omitted. That is to say, if no OT/DT was worked on the first job, don't send that field in the message. Or, if only one job was worked that day, don't send the other seven rows.
This is what I've got so far:
$replyemail="accounting email";
$thesubject = "Daily Timesheet Submission";
$yourname = $_POST["yourname"];
$date = $_POST["date"];
$jb1 = $_POST["jb1"];
$ds1 = $_POST["ds1"];
$st1 = $_POST["st1"];
$ot1 = $_POST["ot1"];
$dt1 = $_POST["dt1"];
<!---SNIP--->
$jb8 = $_POST["jb8"];
$ds8 = $_POST["ds8"];
$st8 = $_POST["st8"];
$ot8 = $_POST["ot8"];
$dt8 = $_POST["dt8"];
$themessage = "Name: $yourname \nDate: $date
\nJob: $jb1 - $ds1 - $st1 hrs - $ot1 hrs - $dt1 hrs
<!---SNIP--->
\nJob: $jb8 - $ds8 - $st8 hrs - $ot8 hrs - $dt8 hrs";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $yourname\nReply-To: $yourname");
header("Location: index.html");
exit();
It sends the message just fine, but the Job: - - hrs - hrs - hrs displays for all eight rows.
I've found this little bit of code on this site (thanks gizmola):
$subject = 'Daily Timesheet Submission';
$replyemail = 'accounting email';
$message = "$date timesheet for $yourname\n\n";
foreach ($_POST as $key => $value) {
$value = trim(strip_tags($value));
if (!empty($value)) {
$message .= "$value\n";
}
}
mail("$replyemail",
"$subject",
"$message",
"From: $yourname\nReply-To: $yourname");
header("Location: index.html");
exit();
But it pushes all data onto a new line. I'd like to keep a similar layout within the email as is shown in the form itself.
I feel this is an easy problem to solve; however, my lack of knowledge leaves me feeling a little embarrassed.
Any help or insight into this matter would be greatly appreciated.
Cheers.