[英]Why is the HTML not being interpreted in this e-mail?
I'm running a website loccaly useing WAMP and have installed Test Mail Server Tool to act as a mail server (all it does is saves the messages as .eml files). 我正在运行一个使用WAMP的网站,并安装了测试邮件服务器工具作为邮件服务器(它只是将邮件保存为.eml文件)。 I've tried opening the messages with Lotus Notes and gmail (web interface) and both do not interpret the HTML, for example instead of having a clickable link they have <a href='localhost'>click here</a>
Did I make a mistake with the headers? 我尝试用Lotus Notes和gmail(web界面)打开消息,并且两者都不解释HTML,例如,而不是有一个可点击的链接,他们有<a href='localhost'>click here</a>
我有没有标题出错?
Here is the code I am using 这是我正在使用的代码
$to = 'bepusslai@fakeinbox.com';
$from = 'From: tester1@localhost.com';
$subject = 'this is a test';
$message = '<html><head></head><body>Hello. Please follow <a href="http://localhost/proc.php?uid=45ab3">this link</a> to activate your account.'
."r\n".'<a href="http://localhost/proc.php?uid=45ab3"><img src="images/ActivateButton.gif" alt="activate button" />
</body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; utf-8' . "\r\n";
$headers .= 'From: testk1@localhost.com' . "\r\n";
mail($to, $subject, $message, $from, $headers);
By the way, I was stuck not having a mail server since WAMP doesn't come with one and I red on another question someone recommended Test Mail Server Tool. 顺便说一句,我被困在没有邮件服务器,因为WAMP没有附带一个,我在另一个问题上有人推荐测试邮件服务器工具。 I'm open to using a different one because it doesn't seem popular. 我愿意使用另一种,因为它似乎不受欢迎。
If you refer to the docs and examples in the docs, you will see that the From information is not a separate argument to mail()
but is included with the additional-headers information. 如果您参考文档中的文档和示例,您将看到From信息不是mail()
的单独参数,但包含在additional-headers信息中。
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) bool mail(string $ to,string $ subject,string $ message [,string $ additional_headers [,string $ additional_parameters]])
Remove your $from argument from the call to mail()
. 从mail()
调用中删除$ from参数。
mail($to, $subject, $message, $headers);
Look at this example , it works for me : 看看这个例子,它对我有用:
<?
//change this to your email.
$to = "m@maaking.com";
$from = "m2@maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = "<html>
<body bgcolor=\"#DCEEFC\">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color=\"red\">Thanks dud!</font> <br>
<a href=\"http://www.test.com/\">* test.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@example.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.