Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2004
    Posts
    72

    PHP: mail() with HTML format?

    I tried many different ways to send email with HTML content but false.

    Thanks who answer this question.

  2. #2
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Simply add a

    Content-type: text/html

    To the mail header, of course if your message is in other character sets than English or contains 8 bit characters it can get a LOT more complicated as you have to start encoding your messages to be RFC compliant.

  3. #3
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100

  4. #4
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Of course if you send an HTML message you should send a plain text part too, but for that you'd have to learn all about MIME multipart messages.

  5. #5
    /* To send HTML mail, you can set the Content-type header. */
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    /* additional headers */
    $headers .= "To: Mary <[email protected]>, Kelly <[email protected]>\r\n";
    $headers .= "From: Birthday Reminder <[email protected]>\r\n";
    $headers .= "Cc: [email protected]\r\n";
    $headers .= "Bcc: [email protected]\r\n";

    /* and now mail it */
    mail($to, $subject, $message, $headers);

  6. #6

  7. #7
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Of course that isn't a mime multipart message, just a MIME html message in a single part.

  8. #8
    Join Date
    Sep 2003
    Location
    London, UK
    Posts
    188
    Rob Johnston | LucidUK.com | [email protected]
    Who is Rob? boobear.co.uk
    MSN: [email protected] | AIM: rob at lucid

  9. #9
    Join Date
    Jan 2004
    Posts
    72
    Originally posted by sagmoh
    /* To send HTML mail, you can set the Content-type header. */
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    /* additional headers */
    $headers .= "To: Mary <[email protected]>, Kelly <[email protected]>\r\n";
    $headers .= "From: Birthday Reminder <[email protected]>\r\n";
    $headers .= "Cc: [email protected]\r\n";
    $headers .= "Bcc: [email protected]\r\n";

    /* and now mail it */
    mail($to, $subject, $message, $headers);
    Thanks, but I have tried this method many times and falsed. I test with Yahoo. I don't know why. I want to write a simple code and want to understand it, some program can send in HTML but it's too complex, I don't understand all the code.

  10. #10
    Join Date
    Feb 2004
    Posts
    772
    Hi mr5,

    Please try the following code:

    <?php
    $subj="subject";
    $header = "Return-Path: [email protected]\r\n";
    $header .= "From: Kristy <[email protected]>\r\n";
    $header .= "Content-Type: text/html; charset=iso-8859-1;\n\n\r\n";

    $mesg = "<html><body>hey! it works!
    </body></html>";

    mail ("[email protected]","$subj",$mesg,$header);
    ?>


    I think this will help you.

    Regards,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •