View Full Version : is it possible to structure an email created from a form?

08-06-2008, 12:26 AM
Hi All,

i have just created a form on my site which is linked to my email address so when the user submits the form it appears in my email, the problem being that it is 1 big paragraph with no formatting, i was wondering if it was possible to add some br or p tags to the code so that each input result is on a seperate line in the email.

here is the code ive got so far


//form processing code - using 'super globals' - Killerphp.com

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comments = $_REQUEST['comments'];

$findus = $_REQUEST['find_us'];
$useful = $_REQUEST['rating'];
$improvments = $_REQUEST['improvments'];
$pros = $_REQUEST['pros'];
$cons = $_REQUEST['cons'];

//print "First name: {$first_name} with an email of : {$email}";

$email_message = "Name: {$name} email address : {$email} subject: {$subject} comments: {$comments} How They Found Us: {$findus} Site Usefulnes: {$useful} Recommended Improvments: {$improvments} Good Points: {$pros} Bad Points: {$cons}";

mail('myemailaddress','Form Responce ', $email_message);


is it possible to add formatting to this code, so that it make the email easier to read?


08-06-2008, 01:15 AM
you should be able to do something like:

$email_message = "<table><tr><td><b>Name:</b></td><td> {$name}</td></tr><tr><td><b>email address:</b></td><td> {$email}</td></tr> etc... ";

sending very basic table based HTML to the recipient.

08-06-2008, 01:33 AM
Sure, just use HTML, and/or CSS as you normally would. Just make sure to escape characters that could disrupt to PHP string, for example, escape the double quotes (") so they don't terminate the string. Remember that some email programs block HTML by default, though. Usually it can't hurt to include it; it may put up the email filesize by a few hundred bytes, but no big deal. If they don't have HTML email, they just won't be able to see the formatting.

08-06-2008, 02:26 PM
brill, thanks for your help guys much appreciated,