vasanth Posted December 27, 2008 Share Posted December 27, 2008 Hi Everyone, I am new to forum, i have been running with problem sending mail using PHPMailer. I am using PHPMailer to send mails, and i have preformatted template for the body of the message that i send. It contains some styles and class applied to some parts of the body in my template. When i send mail to (gmail, yahoo, etc...) i am receiving mail in the format i have designed, but as a plan text format without styles and classes that i have applied for the body of the mail. I even tried sending the styles and the CSS in the body but it didn't solve my problem and also i have set "Content-type: text/html", no use. Please help me solving the problem. Thanks in advance.... Link to comment https://forums.phpfreaks.com/topic/138572-sending-mail-with-css/ Share on other sites More sharing options...
vicodin Posted December 27, 2008 Share Posted December 27, 2008 Is there an email client you have gotten it to work in? Link to comment https://forums.phpfreaks.com/topic/138572-sending-mail-with-css/#findComment-724556 Share on other sites More sharing options...
hobeau Posted December 27, 2008 Share Posted December 27, 2008 Hi vasanth, HTML emails are tricky because of the fact that most email clients are running older versions of browsers and that web clients strip out alot of the html content before displaying it. A few best practices to keep in mind: 1. Do NOT include css in the <head> tag of your html as most email clients strip this out. Instead, include a <style> tag just underneath the <body> tag. I know this is yucky and you won't like doing it, but it works. 2. Do NOT use css positioning. This breaks in most email clients. 3. DO use tables. I know that web development has moved on from table based design, but email clients havn't yet. Keep your tables simple. 4. DO use inline CSS. If you must use CSS, use it inline if possible. The <style> tag just beneath the <body> tag works most of the time, but there are hundreds of different email clients out there and absolutely NO standard between them, so you just have to play around with it. 5. DO use externally hosted images with full paths (http://www.mysite.com/myimage.jpg). Most email clients will not display images as attachments for whatever reasons. 6. NEVER use javascript in an HTML email as this will most certainly be stripped out by the email client. There are some people who do design elements with javascript and this just doesn't work in email. 7. DO use style properties such as border="0" etc... I know everyone is now used to using CSS but keep in mind that email clients are older versions of browsers and they aren't used to CSS. 8. DO use <font> tag. Again, older browsers. 9. Do NOT use <div> tags where possible. At least use them sparingly. Again, div tags usually require positioning that you do not want to use in html emails. 10. Do NOT use shorthand CSS. Many email clients can't read shorthand css. There are just a few of the rule of thumbs. I hope this helps!! Link to comment https://forums.phpfreaks.com/topic/138572-sending-mail-with-css/#findComment-724568 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.