2014-10-03 79 views
-1

以下是與發送郵件相關的PHP代碼,除非鏈接不顯示,否則此代碼運行良好。它像一個正常的文本。此外,還會在代碼中顯示中斷標籤。我認爲錯誤是在消息字符串中。我可以知道如何解決這個問題。如何在字符串中包含href鏈接?

if(isset($_POST['submit'])){ 
    $from = "#"; // sender 
    $to=$email; 
    $subject="Email verification"; 
    $message='Hi, <br/> <br/> We need to make sure you are human. Please verify your email and get started using your Website account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.'</a>'; 

    $message = wordwrap($message,50); 
    mail($to,$subject,$message,"From: $from\n"); 
+1

你必須用'text/html'發送一個頭文件'Content-Type'。以便客戶知道他們必須以HTML格式閱讀電子郵件。 mail()的第四個參數爲您提供發送頭文件的可能性。 – TiMESPLiNTER 2014-10-03 14:29:27

回答

3

您發送的電子郵件爲純文本,而不是HTML。因此,HTML只顯示並不呈現。

$from = "#"; // sender 
$to  = $email; 
$subject = "Email verification"; 
$message = 'Hi, <br/> <br/> We need to make sure you are human. Please verify your email and get started using your Website account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.'</a>'; 
$msg  = wordwrap($message,50); 
$headers = "From: " . $from . "\r\n"; 
$headers .= "Reply-To: ". $from . "\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

mail($to,$subject,$message,$headers); 
+0

我只是準備打出一個,但你已經覆蓋它;)OP的良好的手中。 – 2014-10-03 14:31:11

+1

誰降低了這個?這是正確的。 – 2014-10-03 14:33:09

+2

可能有人試圖搞笑。我會高興。 – Daan 2014-10-03 14:33:28