簡體   English   中英

在php郵件中構建帶變量的html鏈接

[英]build html link with variable inside php mail

使用PHP郵件功能,我需要發送一封電子郵件,其中包含一個返回已修改記錄的鏈接,該鏈接將需要包含在數據庫上修改的記錄的$ id。

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

mail('test@domain.com', '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
mail('test@domain.com', '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");

你可以發送簡單的鏈接。 但在某些電子郵件中可能無法點擊。 所以你必須發送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 = 'test@domain.com';

$subject = 'Visitor Record Updated';

$headers = "From: noreply@domai.com\r\n";
$headers .= "Reply-To: info@yourdomain.com\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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM