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

PHPHTML

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon
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
Armand G

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
solunatec

ASKER
<style type='text/css">

did not work, gave me an error in my editor...and browser
plain old <style> did though....???
Marco Gasi

What editor? What error?
Your help has saved me hundreds of hours of internet surfing.
fblack61
SOLUTION
Prograministrator

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Prograministrator

The error is double quotes,

I replaced it with single quote.
Armand G

Yes, Thanks for that.
solunatec

ASKER
Yes it was the double quotes: thanks everyone....
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Marco Gasi

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
Marco Gasi

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