我尝试做自己的研究,但以下链接对我没有帮助。
PHP Email & Hyperlinks PHP: Send mail with link
$subject = "Thank you for registering to " . SITE_NAME;
$mail_content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>' . $user->first_name . ' ' . $user->lastname_name . ', thank you for registering to ' . SITE_NAME . '.</p>
<p>Please click the following link to proceed to the Questionnaire "<a href =\"www.example.com\">www.example.com</a>"</p>
</div>
</body>
</html>';
在电子邮件中,我希望有链接URL,当用户点击它时,他会被重定向到URL页面。在我检查它的这一刻,我收到了电子邮件,但链接是纯文本,周围有引号。像这样&#34; www.example.com&#34;
我做错了什么?
答案 0 :(得分:3)
删除
中双引号的转义符"<a href =\"www.example.com\">www.example.com</a>"
^ ^
并添加http://
或https://
"<a href ="http://www.example.com">www.example.com</a>"
或
<a href ="http://www.example.com">www.example.com</a>
如果你不想引用它。
经测试:(并假设您的SITE_NAME
constant已经定义,以及其他变量。)
<?php
define("SITE_NAME", "Our Website!"); // I added that
$subject = "Thank you for registering to " . SITE_NAME;
$mail_content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>' . $user->first_name . ' ' . $user->lastname_name . ', thank you for registering to ' . SITE_NAME . '.</p>
<p>Please click the following link to proceed to the Questionnaire "<a href ="http://www.example.com">www.example.com</a>"</p>
</div>
</body>
</html>';
echo $mail_content;
答案 1 :(得分:0)
我在使用php发送电子邮件时遇到类似问题,我使用stripslashes()
电子邮件正文并且它有效。你也可以尝试看看哪个适用于你
$mail_content = stripslashes($mail_content);