Closed Thread
Results 1 to 15 of 15

Thread: Using HTML in mail()...

  1. #1
    Member Niaad is an unknown quantity at this point
    Join Date
    Mar 2001
    Location
    Oswego, IL
    Posts
    52

    Question

    I know that to send mail in PHP, you can use this function:

    Code:
    mail("$to","$subject","$body");
    What I don't know how to do is make that send the email in HTML format, that way I can use HTML tags, so everything isn't all run together.

    Any help would be much appreciated, as I have attempted using HTML tags (including <html> and </html> to start and stop HTML) in the email, but it just all comes through as plain text.

    I have a feeling I am making some really stupid oversight, but would somebody give me a hint as to what that oversight is?
    | n i c k |
    www.niaad.com

  2. #2
    FWS Addict atlas has a spectacular aura aboutatlas has a spectacular aura about atlas's Avatar
    Join Date
    Nov 2000
    Posts
    501
    It depends on the content-type headers that are sent with the message. It appears that PHP just sends messages with
    Code:
    Content-Type: text/plain
    Most messages with HTML code have
    Code:
    Content-Type: multipart/alternative
    as the main content-type of the message, then there is another attachment which is identified by a
    Code:
    Content-Type: text/html
    ---
    In PHP
    Code:
    mail($to,$subj,$message,"Content-Type: text/html");
    ---

    Plain text emails are way better though

    -mk
    atlascgi.com

    [Edited by atlas on 03-23-2001 at 07:26 PM]

  3. #3
    Member Niaad is an unknown quantity at this point
    Join Date
    Mar 2001
    Location
    Oswego, IL
    Posts
    52

    Wink

    lol, if they are way better, is there anyway to make it so all of the data sent to me isn't all run together?
    | n i c k |
    www.niaad.com

  4. #4
    FWS Addict Koolguy is an unknown quantity at this point Koolguy's Avatar
    Join Date
    Oct 2000
    Location
    Canada
    Posts
    934
    \n i think

    [Edited by Koolguy on 03-24-2001 at 08:25 PM]
    koolplace\dot\com - an amazingly awesome, pointless site

  5. #5
    Member Niaad is an unknown quantity at this point
    Join Date
    Mar 2001
    Location
    Oswego, IL
    Posts
    52
    Ah, thank you! I used \n instead, because I've seen that used in PHP before, and it works great.

    Thanks everybody! (This forum rules )
    | n i c k |
    www.niaad.com

  6. #6
    Nice Shot cowax is just really nicecowax is just really nicecowax is just really nicecowax is just really nice cowax's Avatar
    Join Date
    Nov 2000
    Posts
    1,079
    Would that with CGI as well?

  7. #7
    FWS Addict atlas has a spectacular aura aboutatlas has a spectacular aura about atlas's Avatar
    Join Date
    Nov 2000
    Posts
    501
    Yep, \n is just the newline character -- not language specific

    -mk
    atlascgi.com

  8. #8
    Nice Shot cowax is just really nicecowax is just really nicecowax is just really nicecowax is just really nice cowax's Avatar
    Join Date
    Nov 2000
    Posts
    1,079
    I meant Content-Type. I tried this but it didnt work:

    Code:
    	open(MAIL, "|$mail_prog -t");
    	print MAIL "To: $recipient \n";
    	print MAIL "From: whoknows99\@hotmail.com \n";
    	print MAIL "Subject: TEST \n\n";
            print MAIL "Content-type: text/html\n\n ";
    	print MAIL "<font color=red>Testing \n\n";
    	close (MAIL);

  9. #9
    FWS Addict atlas has a spectacular aura aboutatlas has a spectacular aura about atlas's Avatar
    Join Date
    Nov 2000
    Posts
    501
    I never send HTML mail, but I'm assuming that you'd need to do the multipart/alternative method I described above.

    PHP probably takes care of that for you.

    -mk

  10. #10
    ლ(╹◡╹ლ) LeX has disabled reputation
    Join Date
    Oct 2000
    Posts
    7,596
    Check out http://php.net/manual/en/function.mail.php and look at the posts below.

  11. #11
    FWS Addict atlas has a spectacular aura aboutatlas has a spectacular aura about atlas's Avatar
    Join Date
    Nov 2000
    Posts
    501
    Originally posted by LeX
    Check out http://php.net/manual/en/function.mail.php and look at the posts below.
    I believe the question was not about PHP anymore -- the PHP question has been answered

    -mk

  12. #12
    Member Niaad is an unknown quantity at this point
    Join Date
    Mar 2001
    Location
    Oswego, IL
    Posts
    52
    lol, yeah, atlas answered it...
    | n i c k |
    www.niaad.com

  13. #13
    ლ(╹◡╹ლ) LeX has disabled reputation
    Join Date
    Oct 2000
    Posts
    7,596
    I thought that maybe you could use a few more features... okay, fine. Just trying to help, sheesh...

  14. #14
    Originally posted by cowax
    I meant Content-Type. I tried this but it didnt work:

    Code:
    	open(MAIL, "|$mail_prog -t");
    	print MAIL "To: $recipient \n";
    	print MAIL "From: whoknows99\@hotmail.com \n";
    	print MAIL "Subject: TEST \n\n";
            print MAIL "Content-type: text/html\n\n ";
    	print MAIL "<font color=red>Testing \n\n";
    	close (MAIL);
    The reason that's not working is that "Content Type" has to be part of the headers...the "\n\n" at the end of line 4 ends the headers...

    Try this instead:

    Code:
      open(MAIL, "|$mail_prog -t");
      print MAIL "To: $recipient \n";
      print MAIL "From: whoknows99\@hotmail.com \n";
      print MAIL "Subject: TEST \n";
      print MAIL "Content-type: text/html\n\n ";
      print MAIL "<font color=red>Testing \n\n";
    As well, I believe (but I'm not positive), that you need proper html coding...using <html> and <body> tags, etc...

  15. #15
    Member lyew is an unknown quantity at this point
    Join Date
    Nov 2000
    Location
    In front of the computer
    Posts
    40
    Just conjecturing...

    I suppose you could use the heredoc syntax to simplify your script.

    For eg.

    <?

    $MessageText <<<EOD
    <p><b>Dear friend, </b></p>
    <p>How are you... blah blah<i>blah</i></p>
    <<<EOD;

    mail("$to","$subject","$MessageText","Content-Type: text/html");


    ?>

Closed Thread

Bookmarks

Posting Permissions

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