PHP supported HTML tags and E-mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sleeve
Forum Newbie
Posts: 17
Joined: Wed Jan 22, 2003 12:39 am

PHP supported HTML tags and E-mail

Post by Sleeve »

Hello,

I'm trying to send an html formatted e-mail via PHP and have run into some problems. I haven't found much on the internet about which tags are supported. My hope was that I could send an HTML formatted e-mail with PHP that is as rich as any web page, complete with CSS styles, layout tables, images and text formatting of my choice.

Is this the case? If so, can someone direct me to a reference or lend me some clarification?

Thanks in advance.

Sleeve
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the mail client decides how it treats the mail not the server-side php-script.
So for example in outlook express the internet explorer engine is used to display html-mail, in mozilla the gecko engine ...and so on. Some security settings might be in effect but besides that it's just another html-document to display ;)
Sleeve
Forum Newbie
Posts: 17
Joined: Wed Jan 22, 2003 12:39 am

Post by Sleeve »

thanks for the reply Volka
That is exactly what I thought too, but when I debug the script I made, I get errors. Here is an example script:

Code: Select all

<? $to = "$sendTo"; $subject = "Important Message"; 
// your message is now in HTML 
$message = "
<html>
<head>
  <title>message</title>
</head>
<body>
vaiables and so fourth
</body>
</html>
";
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: You <you@you.com>\r\n";
$headers .= "Cc: notyou@you.com\r\n";
$headers .= "Reply-To: $s_name <$s_mail>\n";
$headers .= "X-Mailer: PHP/" . phpversion() . "\n";
$headers .= "X-Priority: 1";
mail("$to", "$subject", "$msg", "$headers"); 
echo "finished!";
?>
If I use any HTML tags in the body such as:

Code: Select all

<tr> 
    <td width="725" height="21">&nbsp;</td>
  </tr>
I get errors when debugging and the script doesn't work.

Any thoughts on this?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I get errors
something specific?
but probably you have problems with nested "s in a double-quoted string literal.
Take a look at the colors the higlighter uses here

Code: Select all

// this produces errors
$message = " 
...
<td width="725" height="21"> </td> 
...";

Code: Select all

// escaping "s within the literal
$message = " 
...
<td width="725" height="21"> </td> 
...";

Code: Select all

// using single-quoted literal (no variable substitution)
$message = ' 
...
<td width="725" height="21"> </td> 
...';
Last edited by volka on Sun Mar 30, 2003 4:48 pm, edited 1 time in total.
Sleeve
Forum Newbie
Posts: 17
Joined: Wed Jan 22, 2003 12:39 am

Post by Sleeve »

I get this:

Parse error: parse error, unexpected T_LNUMBER in c:\inetpub\wwwroot\call_form.php on line 10
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ooops, I was too slow. take a look at my last post ....and http://www.php.net/manual/en/language.types.string.php
Sleeve
Forum Newbie
Posts: 17
Joined: Wed Jan 22, 2003 12:39 am

Post by Sleeve »

all I can say is...Niiiice. You da man!
Post Reply