Posted on 2009-04-21
Last Modified: 2012-05-06
Hi Experts

I am looking for the best solution to use in order to include css styling in html emails that I am sending using PHPMailer.

There seem to be many options and many different ways that clients could potentially handle them.

Most of the suggestions point to using inline styles but others embed, link etc.

What would you suggest as being the best option to go for?
Question by:sirnutty1
    LVL 8

    Expert Comment

    If it is simple content you are sending a quick inline style should do the trick. I usually use a styled <div style=""></div> block when sending short emails.

    Author Comment

    Many thanks for your response aldanch.

    How about if the content is more complicated. There will of course be some simpler variations but for our weekly newsletter, it would nice to use something will a little design.
    LVL 8

    Accepted Solution

    You should be able to send full pages just fine... as long as it is plain HTML. I use PHPMailer as well and IMO it's one of the best.

    If you already have a sample newsletter you could do a quick test? If it seems to work ok then go with it :D

    require "/class.phpmailer.php";
    $mail = new PHPMailer();
    $mail->From = "";
    $mail->FromName = "My Name";
    $mail->Subject = "My Subject";
    $mail->Host = "";
    $mail->Mailer = "smtp";
    $mail->AddAddress("", "Recipient Name");
    $mail->Body = file_get_contents("mynewsletter.html");

    Open in new window


    Author Comment

    Many thanks aldanch

    Just did the test as suggested and with a little tweaking, I think that it will work fine. Can you just clarify one extra point for me?

    Does it make any difference if the html doesn't have HTML, HEAD or BODY tags in it?

    Sincere thanks again for your help.
    LVL 8

    Expert Comment

    Honestly, I don't know. I have sent HTML formatted email using (like I said previously) just plain inline styled DIVs and it appeared to work just fine. I am guessing you could leave out the <html> and <head> tags unless you have CSS in your head.

    I am glad I could help! Good luck :)

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now