2014-01-19 45 views
0

使用PHP郵件功能我需要發送一封包含鏈接的電子郵件回到已修改的記錄,鏈接將需要包含記錄的$ id在數據庫上修改。使用PHP郵件中的變量生成html鏈接

到目前爲止,我已經構建了電子郵件,但是我不確定如何將鏈接包含在變量中。

mail('[email protected]', 'Visitor Record Updated', "Hello,\r\n\r\nThe visitor record for " . $firstname . " " . $lastname . " Has been updated.\r\n\r\nYou can view the changes" . $url ."\r\n\r\nThank You"); 

這就是我的計劃有電子郵件發送,但我怎樣才能建立$ url變量,以便它發送的鏈接作爲

http://app.site.com/visitor-view.php?id=$id 

回答

2
mail('[email protected]', 'Visitor Record Ppdated', "Hello,\r\n\r\nThe visitor record for " . $firstname . " " . $lastname . " Has been updated.\r\n\r\nYou can view the changes: http://app.site.com/visitor-view.php?id=" . $id ."\r\n\r\nThank You"); 
+0

你也可以將鏈接點擊:

從上面的鏈接我對你的問題有所準備click here GuyT

0

您可以發送簡單的鏈接。但在某些電子郵件提供中可能無法點擊。 所以你要發送的HTML郵件:

請參考下鏈接查看更多細節

http://css-tricks.com/sending-nice-html-email-with-php/ 

如果你想添加CSS,那麼你可以添加爲內聯樣式。

**準備電子郵件的內容**

$content ="<html><head><title>Welcome to Mysite</title></head> 
<body> 
<p>Hello,<br/><br/> 
    The visitor record for " . $firstname . " " . $lastname . " Has been updated.<br/><br/> 
    You can view the changes <a href='".$url."'>Here</a></p> 

<p>Thank You</p> 
</body></html>"; 


$to = '[email protected]'; 

$subject = 'Visitor Record Updated'; 

$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

mail($to, $subject, $content, $headers);