我目前正試圖讓通過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