[英]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.