[英]Using HTML in PHP Email Script
I'm trying to add some mark-up to an email that's generated by a PHP script, but it doesn't appear to be parsing the tags as they are are visible in the email along with the content. 我正在尝试向PHP脚本生成的电子邮件中添加一些标记,但是由于它们与内容一起在电子邮件中可见,因此它似乎没有解析标记。 Any help would be really appreciated.
任何帮助将非常感激。 Thanks!
谢谢!
Script: 脚本:
<?php
$name = Trim(stripslashes($_POST['name']));
$email = Trim(stripslashes($_POST['email']));
$message = Trim(stripslashes($_POST['message']));
$emailFrom = $email;
$emailTo = "my@email.com";
$subject = "Subject Line";
// Prepare email body text
$body = "<strong>Name:</strong> $name <br /> Email: $email <br /> Message: $message";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Send email
$success = mail($emailTo, $subject, $body, "From: $name <$emailFrom>");
// Redirect to success or error pages
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
Output: 输出:
<strong>Name:</strong> My Name <br /> Email: my@email.com <br /> Message: TEST
in your code, you don't use $headers 在您的代码中,您不使用$ headers
change these lines : 更改这些行:
$headers = "";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name <$emailFrom>" . "\r\n";
// Send email
$success = mail($emailTo, $subject, $body, $headers);
and if it's not enough to work, I advice you tu use a opensource mailer like phpmailer : http://phpmailer.worxware.com/index.php?pg=examples 如果工作还不够,我建议您使用像phpmailer这样的开源邮件程序: http ://phpmailer.worxware.com/index.php?pg= examples
You are not passing the $header
to you mail function. 您没有将
$header
传递给您的邮件功能。 Please add "From: $name <$emailFrom>"
to your $header
and then pass it to the mail function: 请在您的
$header
添加"From: $name <$emailFrom>"
,然后将其传递给mail函数:
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $name <$emailFrom>" . "\r\n";
// Send email
$success = mail($emailTo, $subject, $body, $header);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.