#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    289
    Rep Power
    0

    Sending mail in text AND html ...


    I searched all night long and can't find a reliable way to do this. Tried many code samples on the web, none of them work.

    I just want a simple way to send an email in both text and html. I want the mail client to decide which one will appear, but not both.

    Here's the code I used

    PHP Code:

    $to
    ="receiver@domain.com";
    $subject="Mail subject here";
    $message="
    --txthtml                                            
    Content-Type: text/plain; charset=\"iso-8859-1\"
    plain text

    --txthtml
    Content-Type: text/html; charset=\"iso-8859-1\"
    <b>HTML</b>
                                                                    
    --txthtml--
    "
    ;

    $extra="From: sender <sender@domain.com>\nX-Mailer: PHP 4.3.2\nMIME-version: 1.0\nContent-Type: multipart/alternative; boundary=txthtml";
                                                                
    mail($to,$subject,$message,$extra)
     or die(
    "an error occured"); 
    This should work, but it's not working at all. The mail is sent empty.

    Someone knows where I can't see my error ... thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    289
    Rep Power
    0
    Ok, I replaced this

    PHP Code:
    --txthtml                                             
    Content
    -Typetext/plaincharset=\"iso-8859-1\" 
    plain text 

    --txthtml 
    Content-Type: text/html; charset=\"iso-8859-1\" 
    <b>HTML</b> 
    for this

    PHP Code:
    --txthtml                                             
    Content
    -Typetext/plaincharset=\"iso-8859-1\" 

    plain text 

    --txthtml 
    Content-Type: text/html; charset=\"iso-8859-1\" 

    <b>HTML</b> 
    a space between them. Now, some content is sent, but only the HTML version. I just see HTML written on the message, when viewed as HTML, everything is fine, but when I switch to plain text in Outlook, I just see HTML in text, I don't even see the <b></b> code.

    Pretty weird ...
  4. #3
  5. No Profile Picture
    Off-topic
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2003
    Location
    UK
    Posts
    1,630
    Rep Power
    1369
    Take a look at the Pear package Mail_Mime - a great class for everything Mime mail releated. Also take a look at the regular Mail package too - invaluble tools for everything mail/php related. These are proven, stable packages. Remember, don't re-invent the wheel!
  6. #4
  7. Rocking my php-ness
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Boston, MA
    Posts
    1,961
    Rep Power
    156
    I'm partial to PHPMailer. I use nothing but http://phpmailer.sourceforge.net/. Simple, fast, can use SMTP, mail(), etc for transfers
    My new WebComic http://www.jjsunshines.com/
    The Geek Shall Inherit the Earth

    It is NOT ok to IM me with questions unless I told you it was ok via PM

IMN logo majestic logo threadwatch logo seochat tools logo