Reputation: 81
Not getting css when i sending mail, only getting html content with no style my php code is as follow,i using phpmailer .so, how to get css style wth my html content? i alreaty try the code by adding $mail->IsHTML(true); but nothing happen............................................
require_once('../class.phpmailer.php');
$mail= new PHPMailer(); // defaults to using php "mail()"
$mail->IsSendmail(); // telling the class to use SendMail transport
$body= file_get_contents('contents.html');
$body= eregi_replace("[\]",'',$body);
$mail->AddReplyTo("[email protected]","First Last");
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo("[email protected]","First Last");
$address = "[email protected]";
$mail->AddAddress($address, "John Doe");
$mail->Subject= "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Html code:
<head>
<style>
#outlook a {
padding:0;
}
body{
width:100% !important;
min-width: 100%;
-webkit-text-size-adjust:100%;
-ms-text-size-adjust:100%;
margin:0;
padding:0;
}
.ExternalClass {
width:100%;
}
.....etc...................
.......................
</style>
</head>
<body>
<table class="body">
<tr>
<td class="center" align="center" valign="top">
<center>
<table class="row header">
<tr>
<td class="center" align="center">
<center>
<table class="container">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td class="six sub-columns">
<img src="http://placehold.it/200x50">
</td>
<td class="six sub-columns last" style="text-align:right; vertical-align:middle;">
<span class="template-label">BASIC</span>
</td>
<td class="expander"></td>
</tr>
</table>
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
<table class="container">
<tr>
<td>
<table class="row">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td>
<h1>Hi, Susan Calvin</h1>
<p class="lead">Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae.</p>
<p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. consequat vel lacus. Sed iaculis pulvinar ligula, ornare fringilla ante viverra et. In hac habitasse platea dictumst. Donec vel orci mi, eu congue justo. Integer eget odio est, eget malesuada lorem. Aenean sed tellus dui, vitae viverra risus. Nullam massa sapien, pulvinar eleifend fringilla id, convallis eget nisi. Mauris a sagittis dui. Pellentesque non lacinia mi. Fusce sit amet libero sit amet erat venenatis sollicitudin vitae vel eros. Cras nunc sapien, interdum sit amet porttitor ut, congue quis urna.</p>
</td>
<td class="expander"></td>
</tr>
</table>
</td>
</tr>
</table>
<table class="row callout">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td class="panel">
<p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. <a href="#">Click it! »</a></p>
</td>
<td class="expander"></td>
</tr>
</table>
</td>
</tr>
</table>
<table class="row footer">
<tr>
<td class="wrapper">
<table class="six columns">
<tr>
<td class="left-text-pad">
<h5>Connect With Us:</h5>
<table class="tiny-button facebook">
<tr>
<td>
<a href="#">Facebook</a>
</td>
</tr>
</table>
<br>
<table class="tiny-button twitter">
<tr>
<td>
<a href="#">Twitter</a>
</td>
</tr>
</table>
<br>
<table class="tiny-button google-plus">
<tr>
<td>
<a href="#">Google +</a>
</td>
</tr>
</table>
</td>
<td class="expander"></td>
</tr>
</table>
</td>
<td class="wrapper last">
<table class="six columns">
<tr>
<td class="last right-text-pad">
<h5>Contact Info:</h5>
<p>Phone: 408.341.0600</p>
<p>Email: <a href="mailto:[email protected]">[email protected]</a></p>
</td>
<td class="expander"></td>
</tr>
</table>
</td>
</tr>
</table>
<table class="row">
<tr>
<td class="wrapper last">
<table class="twelve columns">
<tr>
<td align="center">
<center>
<p style="text-align:center;"><a href="#">Terms</a> | <a href="#">Privacy</a> | <a href="#">Unsubscribe</a></p>
</center>
</td>
<td class="expander"></td>
</tr>
</table>
</td>
</tr>
</table>
<!-- container end below -->
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
Upvotes: 1
Views: 10583
Reputation: 41
I have found that some email clients such as Gmail and Hotmail only respond to inline css sadly. However in essence if you know the CSS you could use inline style for each html element. That's really the best advice I can give.
Upvotes: 0
Reputation: 111869
It is not connected with PHPMailer. If you send e-mail as HTML PHPMailer simple sends your data, not changing your code.
You should change <style>
into <style type="text/css">
to make sure all e-mail clients won't have problem with understanding your style.
Second thing is that you should test your code with some other CSS properties as background-color
or color
for instance.
However some parts of CSS codes simple won't work. E-mail clients are not browsers, so to be maximum compatible with e-mail clients you need to often use code like this:
<table cellpadding=0" cellspacing="0" width="700" align="center" border="0" bgcolor="#ffffff">
instead of using nice CSS
Upvotes: 2
Reputation: 37770
I think you're using an old version of PHPMailer, or at least old example code.
Don't use ereg* functions - they have been deprecated for years.
PHPMailer does not touch your HTML, only encodes it correctly, so anything you are seeing is down to server-side filtering before it gets to inboxes, or client limitations like @SLaks says.
I see you are using Zurb's Ink framework (good choice), but you need to run it through their inliner to make CSS work reliably, particularly in gmail.
For testing that your content is being delivered cleanly, test with something like Apple Mail, which has the best rendering of any client and doesn't mess with your content at all. Gmail does not strip styles, but it does strip classes and ids, making CSS useless unless you inline everything or only use tag-based selectors.
Upvotes: 2