使用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
答案 0 :(得分:2)
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");
答案 1 :(得分: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 = '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);