Solved

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

Posted on 2010-11-16
10
273 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 250 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 31

Expert Comment

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

Assisted Solution

by:Prograministrator
Prograministrator earned 250 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

617 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