2014-05-05 14 views
0

發送電子郵件時,我想顯示超鏈接值而不是整個href。 這是我的代碼在PHP郵件正文中只打印鏈接名稱不是整個href

if ($model->update(array('status'))) 
{ 
    $body.="Your account has now been verified. Please, login and spiff up your profile and take a look at our ,"; 
    $body.="<a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>"; 
    $body.="to start building your business!"; 
    $email=$model->email; 
    mail($email,$subject,$body,$headers); 
    //----------------------------------------------------------// 
    $this->redirect($model->user_id); 
} 

我想給贊助的方案不是在郵件正文整個HREF。但每當我發送一封電子郵件使用它它打印<a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>";而不是Sposorship Program

我試圖在單引號內添加雙引號,但它沒有奏效。

+3

你把它作爲'text'或'html'郵件? – Jurik

+0

我實際上下注了文字。如果你使用PHPMailer添加:'$ mail-> IsHTML(true);'然而代碼似乎你不... – Moby04

回答

1

您需要添加到標題:

$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; 

如果你還沒有這麼做過。

此外,您還必須確保您的電子郵件客戶端已正確設置。例如,在Mozilla Thunderbird中,您可以將其設置爲僅顯示TXT,然後可以對內容進行一些更改。否則,你可能正確地發送電子郵件,但你會造成你不基於http://php.net/manual/en/function.mail.php

您需要通知的郵件引擎,您要發送更復雜的東西,然後只是文字期待

1

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Mail it 
mail($to, $subject, $message, $headers); 
1

您以純文本形式發送郵件,因此無法識別html。以下內容添加到$頭:

$header = 'MIME-Version: 1.0' . "\r\n"; 
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

http://www.php.net/manual/en/function.mail.php