2012-06-12 110 views
-4

看看這個代碼:功能郵件()

$to="$email"; 
$sub="Hi"; 
$mex="hi <br /> \"<a href='http://exemple.com/ver.php?id=$cod'</a>"\"; 
$int = "From:[email protected]"; 
$int .= "Reply-To:[email protected]"; 
$int .= "X-Mailer: PHP/".phpversion(); 
mail($to, $sub, $mex, $int); 

的錯誤是$ MEX,我認爲這是對"<a href.."

如何解決這一問題?

+1

您甚至沒有嘗試添加報價並使用語法突出顯示來查看代碼錯誤.. – Gntem

回答

0
$to="$email"; 
$sub="Hi"; 
$mex="hi <br /> <a href='http://exemple.com/ver.php?id=$cod'>something</a>"; 
$int = "From:[email protected]"; 
$int .= "Reply-To:[email protected]"; 
$int .= "X-Mailer: PHP/".phpversion(); 
mail($to, $sub, $mex, $int); 
2
$mex="hi <br /> \"<a href='http://exemple.com/ver.php?id=$cod'></a>\""; 

你放錯位置的最後一個反斜槓(\),它應該被用來逃避";

注意:使用庫如Swiftmailer而不是mail()將使您的生活更容易。 例如加入標題(您應該在每個標題後添加CRLF,如manual page所述)。老實說,我認爲初學者根本不應該使用mail()函數。去過也做過。

2

嘗試這樣

$mex="hi <br /> \"<a href='http://exemple.com/ver.php?id=$cod'</a>\""; 
0
$mex="hi <br /> \"<a href='http://exemple.com/ver.php?id=$cod'</a>"\"; 

應該

$mex= "hi <br/><a href='http://exemple.com/ver.php?id=$cod'>something here</a>"; 

無需包圍在引號<a href ... ></a>,你可能想要把東西在></a>中間允許用戶點擊

0
$mex="hi <br /> <a href=\"http://exemple.com/ver.php?id=$cod\">Your link text HERE</a>"; 

而且頭應該由換行符結束:

$int = "From:[email protected]\n\r"; 
$int .= "Reply-To:[email protected]\n\r"; 
$int .= "X-Mailer: PHP/".phpversion()."\n\r"; 

\n\r換行符是OS相關的,這適用於Windows,UNIX的使用只能\n\n\n