how to send html 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
phpnewbie2
Forum Newbie
Posts: 2
Joined: Wed Jun 25, 2003 3:56 pm

how to send html mail

Post by phpnewbie2 »

Guys, I keep getting this error with the code below, please help.

"Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' "
------------------------------------
<?php
$smtp="xxx.xxx.com";
$mail_form="xxxnewsletter@xxx.com";

$to = "xxx@xxx.com";
$subject = "Subscribe to xxx Newsletter";


ini_set("SMTP", $smtp);
ini_set("sendmail_from", $mail_form);


$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

mail($to, $subject, "<html>
<head>
<title>Subsribe to xxx Newsletter</title>
</head>
<body>
<p>
<br>Title: <b><?php echo $_POST["title"]; ?></b>
<br>Name: <b><?php echo $_POST["name"]; ?></b>
<br>Company: <b><?php echo $_POST["company"]; ?></b>
<br>Address: <b><?php echo $_POST["address1"]; ?></b>
<br>City: <b><?php echo $_POST["city"]; ?></b>
<br>State: <b><?php echo $_POST["state"]; ?></b>
<br>ZIP: <b><?php echo $_POST["zip"]; ?></b>
<br>Country: <b><?php echo $_POST["country"]; ?></b>
<br>Phone: <b><?php echo $_POST["phone"]; ?></b>
<br>E-Mail: <b><?php echo $_POST["email"]; ?></b>
</body>
</html>", $headers);
?>
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post by Galahad »

Well, you don't need the "<?php" and "?>" tags in your message, because you are still in php mode there. Something like:

Code: Select all

<br>Title: <b>".$_POST&#1111;"title"]."</b>
should work better.
tal3323
Forum Newbie
Posts: 5
Joined: Wed Jun 25, 2003 4:03 pm

Hmmm...let's see...

Post by tal3323 »

To reduce confusion, I'd recommend putting the body of the message into one string variable like $message, ie:

$message = "<head>"
.= "<title>Subscribe to xxx Newsletter</title>"...and so forth.

then use that in the mail function
mail($to, $subject, $message, $headers);

Also, you can get rid of the <?php ?> brackets as someone has already mentioned.
phpnewbie2
Forum Newbie
Posts: 2
Joined: Wed Jun 25, 2003 3:56 pm

Post by phpnewbie2 »

Galahad wrote:Well, you don't need the "<?php" and "?>" tags in your message, because you are still in php mode there. Something like:

Code: Select all

<br>Title: <b>".$_POST&#1111;"title"]."</b>
should work better.
Thanks Galahad, I finally got it to work!
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

Galahad wrote:Well, you don't need the "<?php" and "?>" tags in your message, because you are still in php mode there. Something like:

Code: Select all

<br>Title: <b>".$_POST&#1111;"title"]."</b>
should work better.
why use multiple? i had something i set up $message="small write up

userame is $user
pass is $pass

validationcode is..."worked fine. why not just go...

$message='<html><head><title>Subsribe to xxx Newsletter</title><body><p><br>Title: <b>'.$_POST["title"].'</b><br /><br>Name: <b>'.$_POST["name"].'</b><br /><br>Company: <b>'.$_POST["company"].'</b><br /><br>Address: <b>'.$_POST["address1"].'</b><br /><br>City: <b>'.$_POST["city"].'</b>
<br>State: <b>'.$_POST["state"].'</b><br /><br>ZIP: <b>'.$_POST["zip"].'</b><br /><br>Country: <b>'.$_POST["country"].'</b><br /><br>Phone: <b>'.$_POST["phone"].'</b><br /><br>E-Mail: <b>'.$_POST["email"].'</b><br /></body></html>'

note my use of <br /> which you forgot. in the future that may be needed. also note the use of ' instead of "
i did that because arrays insside fo " got me and i decided it's neater just to get out of the string, and since i don't want a chace at that being evaluated cause everything evaluated is outside, i used '

personally i feel itt's neater code, if you make a mistake that you're more likely to see it that way..at least that's my personal opinion (and i do expect you'll test it with yourself at some point
Post Reply