PDA

View Full Version : styling contact form that is sent to my email account


dazzclub
03-23-2007, 10:34 AM
hi guys,

i ve got a standard form that is sent to my email account and at the mo, it looks pretty plain and boring. as seen below.

Contact Form:

FullName: darren azzopardi

Address1: xxx
Address2: xx
Address3: xxx

Postcode: xx

Email: xxx.

is there a way of presenting this any better such as styling the font or colour? Below is a slice of the php code.


$Body .= "FullName: ";
$Body .= $FullName;
$Body .= "\n";
$Body .= "\n";

$Body .= "Address1: ";
$Body .= $Address1;
$Body .= "\n";
$Body .= "\n";
$Body .= "Address2: ";
$Body .= $Address2;
$Body .= "\n";
$Body .= "\n";
$Body .= "Address3: ";
$Body .= $Address3;
$Body .= "\n";
$Body .= "\n";

Cheers

davidj
03-23-2007, 10:52 AM
you can incorporate HTML for those people who view their mail this way. The trouble is for those people who view their mail text only will see the tags.

example...
taken from http://uk.php.net/function.mail (http://uk.php.net/function.mail)

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

dazzclub
03-23-2007, 11:46 AM
Cheers for that, most email packages, hotmail, yahoo and outlook can all render html within email cant they.

So to put a font or colour i would simply write it as if it was html?

cheers

davidj
03-23-2007, 11:49 AM
yes in the tag

although you can use CSS

domedia
03-23-2007, 03:55 PM
Email clients are notorious for buggy CSS support. HTML emails is one of those weird occurrences where tables are best. I don't like, but it's the way it is :-(
So use of <font> and <table> is actually recommended..