[英]PHP variable in html href
我正在使用HTML电子邮件模板通过电子邮件进行帐户验证
因此,在我的“ register_session.php”中,我集成了PHPMailer以及所有这些,以便向用户发送电子邮件。 我有以下代码:
$email = $_REQUEST['email']; //to
$subject = 'Account Verification';
$message = file_get_contents('../emailhtml.php', FILE_USE_INCLUDE_PATH);
$header = 'From:Test' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1\r\n'; //set FROM HEADER
mail ($email, $subject, $message, $header);
在$message
我使用file_get_contents
来检索emailhtml.php
的html代码。 在emailhtml.php
里面,我有html&css代码。 见下文:
<?php
include("../web/Includes/database_master_mysql.php");
$database_master = new DatabaseMaster();
$email = $_GET['email'];
$code = $_GET['code'];
?>
<html>
<head></head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="50%" class="emailButton" style="background-color: #3498DB;">
<tr>
<td align="center" valign="middle" class="buttonContent" style="padding-top:15px;padding-bottom:15px;padding-right:15px;padding-left:15px;">
<a style="color:#FFFFFF;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:20px;line-height:135%;" href=" <?php echo'http://localhost/web/web/emailactivate.php?email='.$email.'&code='.$code.'';?> ">Confirmation</a>
</td>
</tr>
</table>
</body>
</html>
我没有放置所有代码,因为我的担忧在我的href标记中,我想在单击用户电子邮件中的按钮时将用户重定向到http://localhost/web/web/emailactivate.php?email='.$email.'&code='.$code.'
但是在我的http://localhost/web/web/emailactivate.php?email%20=%3C?php%27.$email.%27?%3E&code=%3C?php%27.$code.%27%20?%3E
显示的是: http://localhost/web/web/emailactivate.php?email%20=%3C?php%27.$email.%27?%3E&code=%3C?php%27.$code.%27%20?%3E
我不太了解PHP,所以如果您能帮助我,那对我来说将意味着一个世界。 谢谢。
首先,将php代码从您的emailhtml.php移至register_session.php,仅将html代码留在那里。
然后为您的mail()函数将其放入变量中,以便您知道是否发送了邮件。
include("../web/Includes/database_master_mysql.php");
$database_master = new DatabaseMaster();
$email = $_GET['email'];
$code = $_GET['code'];
//$email = $_REQUEST['email']; //don't need this line. it's already set from the url request above.
$subject = 'Account Verification';
$message = file_get_contents('../emailhtml.php', FILE_USE_INCLUDE_PATH);
$header = 'From:Test' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1\r\n'; //set FROM HEADER
$send=mail ($email, $subject, $message, $header);
if($send){
//email was successfully sent, do something
} else {
//email did not send, check logs for errors
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.