• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

format form responses when emailing via php

I have a form which emails user inputs via php. I'd like to be able to format those responses considerably using html so that the email isn't just a bland list of responses.

Could anyone point me to a relevant tutorial or an example that I could back engineer to see how this is done.

cheers.
0
robyndorn
Asked:
robyndorn
  • 3
  • 2
1 Solution
 
Jason C. LevineNo oneCommented:
Hi Robyn,

Look at the following:

http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php

and Example 1117. Sending HTML email

on the mail() manual page:

http://us2.php.net/function.mail

Essentially, all you need to do is send an extra couple of headers to the mail() function so the clients know to render the HTML as HTML.
0
 
robyndornAuthor Commented:
Thanks for the fast response jason1178. And I had actually been through that, being new to all this however I still think I'm missing something. I can see how to include html in an email when the html is included in the php script. But I'm missing how to include within that html 'user responses'.

I guess I'm looking at this one in particular:

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

the html section includes no user responses. I'm sure I'm missing something blatantly obvious.
0
 
Jason C. LevineNo oneCommented:
Not blatantly obvious, but not that hard once you see it:

$message = "<html><head><title>A message</title></head><body><p>$_POST['message']</p></body></html>";

Just add the PHP code for your posted form variables to the HTML and make sure to use double-quotes so the PHP code gets evaluated.  In other words this:

$message = "";

not this:

$message = '';
0
 
robyndornAuthor Commented:
you're awesome! :)
0
 
Jason C. LevineNo oneCommented:
Finally, someone who appreciates me.

Can I pay you to talk to my wife? :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now