Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-16
10
Medium Priority
?
276 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:solunatec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:Prograministrator
ID: 34147791
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/
0
 
LVL 7

Accepted Solution

by:
armchang earned 1000 total points
ID: 34148469
Hi,

The above code may not be complete. You need to specify also the type='text/css' inside the <style></style> tags like this inside the <head></head> tags:

<style type="text/css">
h1 {color:red}
p {color:blue}
</style>

Open in new window

0
 

Author Comment

by:solunatec
ID: 34149512
<style type='text/css">

did not work, gave me an error in my editor...and browser
plain old <style> did though....???
0
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!

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 34149590
What editor? What error?
0
 
LVL 3

Assisted Solution

by:Prograministrator
Prograministrator earned 1000 total points
ID: 34149597
Yep, that's right,

type is a required attribute in <style> tag

Thanks  @armchang

@solunatec : this should working well :

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

$message = "
<html>
<head>
<title>HTML email</title>
<style type='text/css'>
.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

0
 
LVL 3

Expert Comment

by:Prograministrator
ID: 34149615
The error is double quotes,

I replaced it with single quote.
0
 
LVL 7

Expert Comment

by:armchang
ID: 34149633
Yes, Thanks for that.
0
 

Author Comment

by:solunatec
ID: 34149654
Yes it was the double quotes: thanks everyone....
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 34149710
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
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 34149730
Ooops, I didn't thought to the others double quotes which styles ones were wrapped in!. I'm sorry.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question