View Full Version : Using HTML in mail()...
Niaad
March 23rd, 2001, 15:45
I know that to send mail in PHP, you can use this function:
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? :)
atlas
March 23rd, 2001, 18:16
It depends on the content-type headers that are sent with the message. It appears that PHP just sends messages with
Content-Type: text/plain
Most messages with HTML code have
Content-Type: multipart/alternative
as the main content-type of the message, then there is another attachment which is identified by a
Content-Type: text/html
---
In PHP
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]
Niaad
March 24th, 2001, 12:16
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?
Koolguy
March 24th, 2001, 12:22
\n i think
[Edited by Koolguy on 03-24-2001 at 08:25 PM]
Niaad
March 24th, 2001, 12:29
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 :) )
cowax
March 24th, 2001, 12:40
Would that with CGI as well?
atlas
March 24th, 2001, 13:30
Yep, \n is just the newline character -- not language specific
-mk
atlascgi.com
cowax
March 28th, 2001, 16:31
I meant Content-Type. I tried this but it didnt work:
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);
atlas
March 28th, 2001, 17:39
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
LeX
March 28th, 2001, 22:45
Check out http://php.net/manual/en/function.mail.php and look at the posts below.
atlas
March 28th, 2001, 23:03
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
Niaad
March 28th, 2001, 23:05
lol, yeah, atlas answered it...
LeX
March 28th, 2001, 23:34
I thought that maybe you could use a few more features... okay, fine. Just trying to help, sheesh...
puDDs
March 29th, 2001, 00:10
Originally posted by cowax
I meant Content-Type. I tried this but it didnt work:
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:
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...
lyew
April 6th, 2001, 01:14
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");
?>
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.