Link to home
Start Free TrialLog in
Avatar of duta1
duta1

asked on

Can feedback be displayed in a table?

Hi!
I just wondered whether a feedback may be displayed in a table, instead of being displayed like as follows:

Thank you, duta1, for your message!

Your e-mail address is: duta1@hotmail.com.

Your message was:
I am testing mysql-php email delivery.

The above feedback was obtained from a feddback form which asked for e-mail address and message to administrator.

If the feedback poured in from, say, thousands of clients, it may be a lot easier to read the feedback when it is displayed in a table as follows:

_____________________________________________
|Thank you, duta1, for your message!                       |
|___________________________________________|
|Your e-mail addres is: duta1@hotmail.com              |
|___________________________________________|
| I am testing mysql-php email delivery                     |
|___________________________________________|
                                 .
                                 .
                                 .
                                 .


Finally, I am looking very much forward to getting your always wonderful idea.

duta1
Sunday, March 20, 2005, at 8:18 p.m.











Avatar of sajuks
sajuks

You could enclose it within table tags for ex: u could've it like this
<TABLE border =1>
<TR>
    <TD>Thank you, <?php echo $_POST['name']; ?> , for your message!</TD>
</TR>
<TR>
    <TD>Your e-mail addres is: <?php echo $_POST['email']; ?></TD>
</TR>
<TR>
    <TD>I am testing mysql-php email delivery</TD>
</TR>
</TABLE>
First, if you have sample code you are trying to modify, that always helps.

Second, the example you give is contradictory.  You talk about 'feedback from thousands of clients', but then your example is table-izing the 'response page' to a feedback form.  I assume you actually mean having an 'administrative page', where feedback is saved into a database, and then you can display up to N feedback entries per page (and flush them when done)?  Like:

[ duta1@hotmail.com                       ][ I am testing mysql-php email delivery                                                             ]
[ someone@hotmail.com                  ][ You might want to use different fonts                                                             ]
[ else@hotmail.com                         ][ If you use tables, administrators can quickly scan for things                              ]
.
.
.

Is that what you are really talking about?

-d
Avatar of duta1

ASKER

Dear sajuks and davebytes:

First to sajuks, I tried your instruction, but it did not work. So I am going to copy my script at the end of this post so that you may take a look.

Second to davebytes, I am sorry to confuse you. What you said is very close to what I want. Yes, feedbacks from thousands of clients needed to be saved in an administrator's directory to be displayed in a table for easy reading.
############ This is feedback form file named "feedback.html"  ##############
<HTML>
<HEAD>
<TITLE>E-Mail Form</TITLE>
</HEAD>
<BODY>
<FORM action="sendmail_mod.php" method="POST">
<p><strong>Name:</strong><br> <INPUT type="text" size="25" name="name"></p>
<p><strong>E-Mail Address:</strong><br> <INPUT type="text" size="25" name="email"></p>
<p><strong>Message:</strong><br>
<textarea name="message" cols=30 rows=5></textarea></p>
<p><INPUT type="submit" value="send"></p>
</FORM>
</BODY>
</HTML>
################# This is "sendmail_mod.php" #############
<html>
<head>
<title> Sending mail from the form in Listing 10.10</title>
</head>
<body>
<Table border =1>
<TR>
<TD> Thank you, <b> <?php echo $_POST['name']; ?> </b>, for your message! </TD>
</TR>
<TR>
<TD> Your e-mail address is: <?php echo $_POST['email']; ?> <?TD>
</TR>
<TR>
<TD> Your message was:<?php echo $_POST ['message']; ?> </TD>

//start building the mail string
//$msg = "Name:    $_POST[name]\n";
//$msg .= "E-Mail:  $_POST[email]\n";
//$msg .= "Message: $_POST[message]\n";
//set up the mail
//$recipient = "duta1@mci.com";
$recipient = "duta1@mci.com";
$subject = "Form Submission Results";
$mailheaders = "From: My Web Site <defaultaddress@yourdomain.com> \n";
$mailheaders .= "Reply-To: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>
############### ########################

What I would like to see is as follows or similar to this (You may give more creative idea):
___________________________________________________
| Feedback from client 1 :                                                   |
|__________________________________________________|
| Feedback from client 2 :                                                   |
|__________________________________________________|
| Feedback from client 3 :                                                   |
|_________________________________________________ |
| Feedback from client 1001 :                                             |
|_________________________________________________|


Many thanks to both of you!

duta1
Sundat at (;48 pm

for ur send mail.php try this
<html>
<title> Sending mail from the form in Listing 10.10</title>
<body>

<?php
if (isset($_POST["submit"]) && $_POST["submit"] != "")
  {
      $msg =  "Name: ".$_POST["name"]."\n";
      $msg .= "Email: ".$_POST["email"]."\n";
      $msg .= "Message: ".$_POST["message"]."\n";
 
      $recipient = "youremail@domain.com";
      $subject = "Form Submission Results";

      $mailheaders = "From: My Web Site".$_POST["email"]."\n";
      $mailheaders .= "Reply-To:".$_POST["email"]."\n\n";

      if(mail($recipient, $subject, $msg, $mailheaders))
           echo "<b> Your request/comment has been sent successfully! </b>";
      else
           echo "<b> Error in sending mail to ".$recipient."! </b>";
  }

else
   {
?>
      <tr>
            <td rowspan="3">&nbsp;</td>
            <td>&nbsp;</td>
      </tr>
      <tr>
            <td>&nbsp;</td>
      </tr>
      <tr>
            <td>&nbsp;</td>
      </tr>


<form method="post" action="">
<TABLE border =1>
<TR><td rowspan="3">Feedback  from Client 1</td>
      <TD rows>Thank you, <?php echo $_POST['name']; ?> , for your message!</TD></tr>
      <tr><TD>Your e-mail addres is: <?php echo $_POST['email']; ?></TD></tr>
      <tr><TD>I am testing mysql-php email delivery</TD></tr>
</TABLE>

<input type="hidden" name="name" value="<?php  echo $_POST['name']; ?>" >
<input type="hidden" name="message" value="<?php  echo $_POST['message']; ?>" >
<input type="hidden" name="email" value="<?php  echo $_POST['email']; ?>" >
</form>

<?php
}
?>

</body>
</html>
Well, you have two choices: write to a file, or write to a database table.  Either can be done right after the call to mail().

if you just want to write to a file, you can just append:

$fp = fopen('feedback.txt', 'a+');
if ($fp) {
  fwrite("$recipient\t$msg\n");
  fclose($fp)'
}

if you want to write to mysql, well, there are a TON of mysql tutorials, so I won't try to duplicate the basics (setting up a database, creating your table, etc...).  For each entry, you'd simply do an insert, like:
mysql_query("INSERT INTO feedback_table (user_email, user_msg) VALUES ('$receipient', '$msg')");

To print from either, you'd have an admin page that grabs an array full of data, then pumps it out in table form.

$data = file_get_contents('feedback.txt', 'r');
echo "<table><tr><th>User</th><th>Message</th></tr>";
$feedback_array = explode("\n", $data);
foreach ($feedback_array as $item) {
  $array = split("\t", $item);
  echo "<tr><td>".$array[0]."</td><td>".trim($array[1])."</td></tr>";
}
echo "</table>";

The database version is similar.  Basic difference is that grabbing the results from a table you can get it already in a parsed format.
The PHP.NET mysql pages have decent examples.  I'm taking a chunk from:
http://us2.php.net/manual/en/ref.mysql.php

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
echo "<table><tr><th>User</th><th>Message</th></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  echo "<tr><td>".$line->user_email."</td><td>".$line->user_msg."</td></tr>";
}
echo "</table>";
mysql_free_result($result);

Something like that as a rough case.
Avatar of duta1

ASKER

Dear davebytes:

Thank you so much for your kind, prompt response. You are just amazing.

By the way, your first code worked just fine: It was displayed in a nice table, but it was not delivered to the recipient's email account.

On your second scripts, I need to take some time to try it. I am so happy to get such a wonderful help from genius like you.

Thanks again!

duta1
Sunday at 10:18 p.m
Avatar of duta1

ASKER

Dear davebytes:

Thanks again for your wonderful help.

I would like you to know that your code worked just fine except that the feedback is not delivered to the recipient's email account.

The original script could not display the feedback in a table, but its feedback delivery to the recipient's email account worked fine.
For your info, the mail delivery part of the orignal code is: mail("shim@mchsi.com", "Feedback Form Results", $message, "From: $email");

Hope that this info might of some help to you in fixing the one remaining problem.

Thanks again!

duta1
Sunday at 10:58 pm
Maybe try smaller changes to your code.  You were missing a number of closing tags, one tag had a typo, etc.

If you wanted to send an HTML email, that's a different story! ;)  But this should get you back where you were originally going.

Note that this is 'minimal' compared to storing and managing the feedback messages outside of emails, as I described above.  Displaying to the USER as a table, or emailing as a table, is not necessary -- outputting for an ADMIN as a table is of great use!

-d

################# This is "sendmail_mod.php" #############
<html>
<head>
<title> Sending mail from the form in Listing 10.10</title>
</head>
<body>

Thank you for your message!

<table>
<TR><TH width="150">Name</TH><TH width="150">Email</TH><TH>Msg</TH></TR>
<TR>
    <TD><?php echo $_POST['name']; ?></TD>
    <TD><?php echo $_POST['email']; ?></TD>
    <TD><?php echo $_POST ['message']; ?></TD>
</TR>
</table>

//start building the mail string
$msg = "Name:    $_POST['name']\n";
$msg .= "E-Mail:  $_POST['email']\n";
$msg .= "Message: $_POST['message']";
//set up the mail
$recipient = "duta1@mci.com";
$subject = "Form Submission Results";
$mailheaders = "From: My Web Site <".$_POST['email'].">\n";
$mailheaders .= "Reply-To: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>
#######################################
Avatar of duta1

ASKER


Dear davebytes:

Thank you so much for your very kind, patient effort to help me out.

By the way, I tried the following code (which you sent me), but it did not work at all: It did not display typed-in feedback in the screen, and it did not send feedback to the recipient's email account.

I inserted "<?" in the middle (right below "</TABLE>").



################ This is "sendmail.php" file  ######################################################
<html>
<head>
<title> Sending mail from the form in Listing 10.10</title>
</head>
<body>

Thank you for your message!

<table>
<TR><TH width="150">Name</TH><TH width="150">Email</TH><TH>Msg</TH></TR>
<TR>
    <TD><?php echo $_POST['name']; ?></TD>
    <TD><?php echo $_POST['email']; ?></TD>
    <TD><?php echo $_POST ['message']; ?></TD>
</TR>
</table>

// I inserted <? right in the next, next  line

<?
//start building the mail string
$msg = "Name:    $_POST['name']\n";
$msg .= "E-Mail:  $_POST['email']\n";
$msg .= "Message: $_POST['message']";
//set up the mail
$recipient = "my_email_address@msi.com";
$subject = "Form Submission Results";
$mailheaders = "From: My Web Site <".$_POST['email'].">\n";
$mailheaders .= "Reply-To: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>

######################### This is "feedback.html" file  ######################

<HTML><HEAD>
<TITLE>E-Mail Form</TITLE>
</HEAD><BODY>

<div align="center">
<table width="350" cellpadding="10" cellspacing="0" border="2">
<tr align="left" valign="top">
<td align="left" colspan="1" rowspan="1"  bgcolor="#64b1ff">

<FORM action="sendmail.php" method="POST">
<p><strong>Name:</strong><br> <INPUT type="text" size="25" name="name"></p>

<p><strong>E-Mail Address:</strong><br> <INPUT type="text" size="25" name="email"></p>
<p><strong>Message:</strong><br>
<textarea name="message" cols=30 rows=5></textarea></p>
<p><INPUT type="submit" value="send"></p>
</FORM>

</td></tr></table>
</div>

<div align="center">
<table width="350" cellpadding="10" cellspacing="0" border="2">
<tr align="left" valign="top">
<td align="left" colspan="1" rowspan="1"  bgcolor="#3a6ea5">


</td></tr></table>
</div>
#############################################################

I truly apprecite your very kind effort to help a true novice like me at this late hour.

duta1

Monday at 12:27 am
I'll go look.  Just in case, change the "<?" you inserted to be "<?php".  In some cases the 'shorthand' doesn't work.
further changes.  I see the table, but my machine here isn't configured for outgoing mail so I don't know if all the mail() fields are correct...

I tried to size things a bit.  Again, using a table here isn't very helpful, as the body of the message really wants to be page-width.  You could go to two columns for the two user fields, then span another row for the message... but that's just going overboard! ;)  You just don't need to be using a table for this 'part' of your overall process.



###################################################
<html>
<head>
<title>Sending Your Feedback</title>
</head>
<body>
<h1>Thank you for your message!</h1>
<table border='1'>
<TR align=left><TH width="150">Name</TH><TH width="200">Email</TH><TH width="350">Msg</TH></TR>
<TR>
    <TD><?php echo $_POST['name']; ?></TD>
    <TD><?php echo $_POST['email']; ?></TD>
    <TD><?php echo $_POST ['message']; ?></TD>
</TR>
</table>

<?php
//start building the mail string
$msg = "Name:    ".$_POST['name'];
$msg .= "\nE-Mail:  ".$_POST['email'];
$msg .= "\nMessage: ".$_POST['message'];
//set up the mail
$recipient = "davebytes@comcast.net";
$subject = "Form Submission Results";
$mailheaders = "From: My Web Site <".$_POST['email'].">\n";
$mailheaders .= "Reply-To: ".$_POST['email'];
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>
#########################################################
ASKER CERTIFIED SOLUTION
Avatar of davebytes
davebytes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of duta1

ASKER

Dear davebytes:

Thank you so so much for your kindness.

I went to bed after sending my last reply to you around 1 a.m. this morning.

I am writing this reply upon checking your reply and testing it at work briefly.

When I clicked "sumit" button, I got an error message, like as follows:
"Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\y\feedback\sendmail.php on line 21".  The error message mya have to do with this computer.
I will come back to you after testing your codes at home this evening.

Thank you very much again!

duta1
MOnday, March 21, at 8:38 am




No problem.  I tested both files, excepting the actual mail call.  And line 21 of that code is a comment??  Odd behavior.  Yeah, let me know this evening.

-d
Last I knew, I had this all working locally, and he was looking into it.  Never heard back.
Avatar of duta1

ASKER

Dear Davebytes:

Thank you so much for your kind, patient help.  You are awesome.

I am also grateful to sajuks too for trying to help me.

I will come back to you with some more requests for help very soon.

Bye for now!

Wednesday (April13, 2005) at 8:43 p.m.