PDA

View Full Version : PHP Sendmail with HTML


adammark
January 14th, 2007, 11:58 PM
I am trying to get my script to send HTML content and display results from variable within the email. However, when I have the email sent my variables show up blank. Anybody have an idea?? My scipt is below

<?php


$email = $HTTP_POST_VARS['email'];
$subject = "Submission";
$name = $HTTP_POST_VARS['name'];
$city = $HTTP_POST_VARS['city'];
$state = $HTTP_POST_VARS['state'];
$country = $HTTP_POST_VARS['country'];
$story = $HTTP_POST_VARS['story'];

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: myemail@mydomain.com' . "\r\n";
$headers .= 'From:$email' . "\r\n";


$message = '
<table cellspacing="2" cellpadding="2" width="100%" bgcolor="#ffffff" border="0">
<tr valign="top">
<td colspan="2"><font face="Arial" color="#000000" size="2">
<div><img height="98" src="..//miniheader.jpg" width="610"></div></font></td></tr>
<tr valign="top">
<td><font face="Arial" color="#000000" size="2">
<div><b>Name:</b></div></font></td>
<td><?=$name?></td></tr>
<tr valign="top">
<td><font face="Arial" color="#000000" size="2">
<div><b>E-mail:</b></div></font></td>
<td><?php $email; ?></td></tr>
<tr valign="top">
<td><font face="Arial" color="#000000" size="2">
<div><b>City:</b></div></font></td>
<td>$city</td></tr>
<tr valign="top">
<td><font face="Arial" color="#000000" size="2">
<div><b>State:</b></div></font></td>
<td>$state</td></tr>
<tr valign="top">
<td><font face="Arial" color="#000000" size="2">
<div><b>Country:</b></div></font></td>
<td>$country</td></tr>
<tr valign="top">
<td><font face="Arial" color="#000000" size="2">
<div><b>Story:</b></div></font></td>
<td>$story</td></tr>
</table></div></font>
';


if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($story == "") {
echo "<h4>Please include your story</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}


elseif (mail('myemail@mydomain.com.net',$subject,$message ,$headers))


{
mail('$email',$subject,"Hello $name,\nHere is a copy of the e-mail you sent through our website.\n\n $message","From: $name <$email>");
print "<meta http-equiv=\"refresh\" content=\"0;URL=../?page=thank\">";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>

Buzz
January 15th, 2007, 02:13 AM
Your variables are not formatted correctly.


<td><?=$name?></td>


should be

<td>'.$name.'</td>


Check all your variables in the $message

You must concatenate the php variables inside the html code, since you are assigning it all to the $message variable.