Link to home
Create AccountLog in
Avatar of solunatec
solunatec

asked on

how to add nice formatting/css etc. to php internet email

I am putting forward this small example to ask how to add styling to php internet email..::


$to='ag@groos.net';
$body=$account_name;
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <admin@groos.net>' . "\r\n";
$headers .= 'Cc: ag@groos.net' . "\r\n";

mail($to,$subject,$message,$headers);

Open in new window

Avatar of Prograministrator
Prograministrator

Simply, add <style> tag inside the <head> tag and style the Email as you want

like this :

$to='ag@groos.net';
$body=$account_name;
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
<style>
.test {
/* style here*/
}
/* and so on*/
</style>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <admin@groos.net>' . "\r\n";
$headers .= 'Cc: ag@groos.net' . "\r\n";

mail($to,$subject,$message,$headers);

Open in new window


And take a look here : http://www.campaignmonitor.com/css/
ASKER CERTIFIED SOLUTION
Avatar of Armand G
Armand G
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of solunatec

ASKER

<style type='text/css">

did not work, gave me an error in my editor...and browser
plain old <style> did though....???
What editor? What error?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
The error is double quotes,

I replaced it with single quote.
Yes, Thanks for that.
Yes it was the double quotes: thanks everyone....
Double quote have never given an error, nor in Netbeans nor in browser (any browser)... not in my experience.
"The most important feature of double-quoted strings is the fact that variable names will be expanded." (http://php.net/manual/en/language.types.string.php)

Cheers
Ooops, I didn't thought to the others double quotes which styles ones were wrapped in!. I'm sorry.