我正在运行一个使用WAMP的网站loccaly,并安装了测试邮件服务器工具作为邮件服务器(它所做的只是将消息保存为.eml文件)。我试着用Lotus Notes和gmail(web界面)打开消息,但它们都不解释HTML,例如,它们没有可点击的链接,而是有<a href='localhost'>click here</a>
。我在标题上犯了错误吗?
这是我正在使用的代码
$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);
顺便说一句,我一直没有邮件服务器,因为WAMP没有邮件服务器。我回答了另一个问题,有人推荐了测试邮件服务器工具。我愿意用另一种,因为它似乎不受欢迎。
如果您参考文档和文档中的示例,您会发现From信息不是mail()
的单独参数,而是包含在附加标头信息中。
bool邮件(string$to,string$subject,string$message[,string$additional_headers[,string$additional-parameters])
从对mail()
的调用中删除$from参数。
mail($to, $subject, $message, $headers);
看看这个例子,它对我有用:
<?
//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....!";
?>