email - Add a button that will be redirected to the other webpage in PHP Mailer with HTML design?
I want to add a button that will be redirected to the other webpage when clicked. It also has a token but it says that my token does not exist. I think the link to my button is not working in my HTML in PHP Mailer.
This is the code of my PHP Mailer:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
function sendemail_verify($name, $email, $verify_token)
{
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
//Recipients
$mail->setFrom('ust.ofad.appsys@gmail.com', $name);
$mail->addAddress($email);
//Content
$mail->isHTML(true);
$mail->Subject = 'Email Verification';
$email_template = '
<html>
<head>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;300;500;700;800&family=Source+Sans+Pro:wght@700&display=swap"
rel="stylesheet"
/>
<style>
/* internal */
body {
width: 100%;
min-height: 100vh;
align-items: center;
display: block;
justify-content: center;
user-select: none;
position: absolute;
top: 80px;
}
table {
border-spacing: 0;
}
td {
padding: 0;
background-color: rgba(247, 189, 22, 0.8);
width: 635px;
width: 655px;
height: 300px;
border-radius: 10px;
margin-top: 7%;
align-items: center;
}
.webkit {
max-width: 600px;
background-color: #ffffff;
}
/* Main */
.main {
font-family: "Montserrat", sans-serif;
}
.main p {
text-align: center;
margin-left: 20px;
margin-right: 20px;
font-weight: 700;
font-size: 14px;
}
.main h1 {
font-size: 25px;
text-align: center;
}
/* Reset Button */
.reset-btn {
background-color: rgba(45, 45, 45, 0.9);
font-size: 14.5px;
color: #fff;
font-family: "Montserrat", sans-serif;
font-weight: 400;
width: 100px;
padding: 8px 60px;
margin: 0 auto;
cursor: pointer;
justify-content: center;
align-items: center;
border: none;
text-decoration: none;
border-radius: 50px;
text-decoration: none;
font-color: white;
}
.reset-btn:hover {
background: rgba(79, 79, 79, 0.9);
color: white;
}
/* Media Queries */
@media screen and (max-width: 600px) {
}
@media screen and (max-width: 400px) {
}
</style>
</head>
<body>
<center class="wrapper">
<div class="webkit">
<table class="main">
<tr>
<td>
<h1>Hi ${name}!</h1>
<p>
You recently registered to OFAD-APPSYS with the email, ${email}.
</p>
<p>You can verify your account by clicking the button below:</p>
<div class="reset-btn" style="text-align: center">
<a href = "http://localhost/appsys/website/verify.php?token=$verify_token">Verify your Email</a>
</div>
<p>
If you did not register to OFAD-APPSYS, please ignore
this email.
</p>
</td>
</tr>
</table>
</div>
</center>
</body>
</html>
</html>
';
$mail->Body = $email_template;
$mail->send();
//echo 'Message has been sent.';
}
And this is the code of my verify.php where the link will be redirected.
<?php
session_start();
include('db.php');
if(isset($_GET['token']))
{
$token = $_GET['token'];
$verify_query = "SELECT verify_token, verify_status FROM register WHERE verify_token='$token' LIMIT 1";
$verify_query_run = mysqli_query($conn, $verify_query);
if (mysqli_num_rows($verify_query_run) > 0)
{
$row = mysqli_fetch_array($verify_query_run);
if($row['verify_status'] == "0")
{
$clicked_token = $row['verify_token'];
$update_query = "UPDATE register SET verify_status='1' WHERE verify_token = '$clicked_token' LIMIT 1";
$update_query_run = mysqli_query($conn, $update_query);
if($update_query_run)
{
$_SESSION['status'] = "Your Account has been verified successfully!";
header("Location: verify-success.php");
exit(0);
}
else
{
$_SESSION['status'] = "Verification failed!";
header("Location: login.php");
exit(0);
}
}
else
{
$_SESSION['status'] = "Email already verified. Please Login";
header("Location: login.php");
exit(0);
}
}
else
{
$_SESSION['status'] = "This token does not exist.";
header("Location: login.php");
}
}
else
{
$_SESSION['status'] = "Not Allowed";
header("Location: login.php");
}
?>
Answer
Solution:
Your link must be somethin like this!
$email_template = '
...
...
...
<a href = "http://localhost/appsys/website/verify.php?token='. $verify_token .'">Verify your Email</a>
Source