我目前正试图让通过PHP邮件功能发送的邮件中的链接工作。这里是我的代码 - 我还包含了一些事情我已经尝试过(与音符一起注释掉):奇怪的行为与PHP邮件功能中的链接
$to = "[email protected]";
$subject = "Testing email";
//$body = '<strong>This is strong text</strong>'; <-- Works
//and the text is correctly emphasised.
//$body = '<a href="www.yahoo.com">Link Test</a>'; <-- Works
//but without http:// at the start makes the link relative to the server root
//$body = "<a href='http://www.yahoo.com'>Link Test</a>"; <-- Does not work
//$body = "<a href=\"http://www.yahoo.com\">Link Test</a>"; <-- Does not work
$body = '<a href="http://www.yahoo.com">Link Test</a>'; //<-- Does not work
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Steven Parler <". $to . ">\r\n";
$headers .= "X-Mailer: PHP/".phpversion() . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
可以看出HTML工作没有链接,链接也提供工作,我不在链接本身中不包含“http://”。如果我确实包含了“http://”,那么根本就没有收到/发送邮件(我不确定哪个邮件()命令返回true表示它已发送)。
我不确定为什么这不起作用。它可能是一些设置,需要改变我的虚拟主机的服务器?我在Windows共享主机上。
在此先感谢任何人可以给我的建议 - 一直把我的头发拉出这个哈哈。 :)
它是做什么的?你根本没有收到信息吗? – Cfreak 2011-02-11 22:14:15
对不起,我应该更具体。是的 - 在那些被标记为“不工作”的邮件中根本没有收到邮件。 – Steven 2011-02-11 22:17:48
链接如何工作,如果他们工作的话,由*客户端*而不是发送邮件的服务器决定。 – Maerlyn 2011-02-11 22:17:56