PHP Sending HTML Formatted Emails

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robbiesmith79@gmail.com

    PHP Sending HTML Formatted Emails

    Just so this is out there on the web, I battled the past 24 hours
    about this. Background info... I developed a ecommerce website in PHP
    4 on a shared linux hosting plan from GoDaddy and had the html
    formatted emails sending as text/html and were going fine with limited
    header information. Then we moved the site over to a Dedicated Linux
    hosting plan. This time, it's PHP 5. Things are bound to not work as
    expected moving to a new programming language.

    So what worked in PHP 4:

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    Now needs to be (at least what worked for me) in PHP 5

    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "X-Priority: 3\n";
    $headers .= "X-MSMail-Priority: Normal\n";
    $headers .= "X-Mailer: php\n";

    For the life of me I could not figure out why text/html formatted
    emails were always sending as plain text and all the information was
    shown in the body text using the PHP 4 method.

    There... I hope I have saved someone else the trouble of losing the
    amount of hair I did over this.

    Rob

  • Manuel Lemos

    #2
    Re: PHP Sending HTML Formatted Emails

    Hello,

    on 03/18/2007 11:24 PM robbiesmith79@g mail.com said the following:
    Just so this is out there on the web, I battled the past 24 hours
    about this. Background info... I developed a ecommerce website in PHP
    4 on a shared linux hosting plan from GoDaddy and had the html
    formatted emails sending as text/html and were going fine with limited
    header information. Then we moved the site over to a Dedicated Linux
    hosting plan. This time, it's PHP 5. Things are bound to not work as
    expected moving to a new programming language.
    >
    So what worked in PHP 4:
    >
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    >
    Now needs to be (at least what worked for me) in PHP 5
    >
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "X-Priority: 3\n";
    $headers .= "X-MSMail-Priority: Normal\n";
    $headers .= "X-Mailer: php\n";
    >
    For the life of me I could not figure out why text/html formatted
    emails were always sending as plain text and all the information was
    shown in the body text using the PHP 4 method.
    >
    There... I hope I have saved someone else the trouble of losing the
    amount of hair I did over this.
    I think the problem has nothing to do with the version but rather with
    the MTA that used in the servers you tried. Depending on the MTA, the
    line breaks may be processed differently.

    Anyway, sending HTML messages like that you will have also message
    filtering problems. You cannot send messages with text/html has main
    content-type. That is not the way common mail programs will send HTML
    formatted messages. Many systems will discard messages composed like
    that because it is a sympthom that you are using a bulk mailing script
    that may be spam.

    What you need to do is to compose a multipart/alternative message that
    encloses a text/plain part and an text/html part. If you do not know how
    to do that, you can try many of the ready to use classes that can
    compose multipart/alternative messages. I use this MIME message class:




    --

    Regards,
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator


    PHP Classes - Free ready to use OOP components written in PHP
    Free PHP Classes and Objects 2026 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials

    Comment

    Working...