开发者

PHP email form - Some get HTML some get Plain Text

I've been trying to figure this one out for a while. Some users are receiving this email (via a Flash form) sent in plain text and others in full HTML (like it sho开发者_JS百科uld).

Would anyone know why this is happening, anything I could fix here and make sure it always get displayed in HTML all the time?

<?php
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
   if(empty($_POST['senderEmail'])){
   echo"no email address found";
   exit;
}
$senderName = $_POST['senderName'];
$senderEmail = $_POST['senderEmail'];
$senderPhone = $_POST['senderPhone'];
$senderMsg = nl2br($_POST['senderMsg']);
$sitename = "somesite";
$to_myself = "myemail";
$to_visitor = $_POST['senderEmail'];
$ToName = "somename";
$date = date("m/d/Y H:i:s");
$ToSubject = "Email From $senderName via $sitename";
$comments = $msgPost;

$EmailBody = "A visitor to $sitename has left the following information<br />
Sent By: $senderName<br />
Email: $senderEmail<br />
Phone: $senderPhone
<br /><br />
Message Sent:
<br />$senderMsg<br />";

$EmailBody_visitor = "You have just left the following information at $sitename <br />
Sent By: $senderName<br />
Email: $senderEmail<br />
Phone: $senderPhone
<br /><br />
Message Sent:
<br />$senderMsg<br />";  

$EmailFooter = "<br />Sent: $date<br /><br />";
$Message = $EmailBody.$EmailFooter;
$Message_visitor = $EmailBody_visitor.$EmailFooter;

$ok = mail($to_myself, $ToSubject, $Message, $headers . "From:$senderName <".$senderEmail.">");
$ok = mail($to_visitor, $ToSubject, $Message_visitor, $headers . "From:$sitename <".$to_myself.">");

if($ok){ 
echo "retval=1";
}else{ 
echo "retval=0";
}

?> 


That's foremost a mail client issue. Most current mail programs can convert HTML mails into plaintext, and if that's the users preferred format, will do.

This is furthered by your mails not being complete html documents. You use just a few <br> tags, not a complete <html> document. You should use a complete html page template. (See http://articles.sitepoint.com/article/code-html-email-newsletters for some overview.)

Third, which you didn't ask for, your script is abusable for sending out spam. There's no visible captcha protection in your code, and the recipient is completely free form. Using this via a Flash form provides some obscurity, but no long-term protection.


I would not use
in your email, as many older email clients won't recognize those are valid tags. It would also be quite useful to see the raw email, after being sent. There may be something interesting going on that is more visible there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜