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('[email protected]', $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");
}
?>
Your link must be somethin like this!
$email_template = '
...
...
...
<a href = "http://localhost/appsys/website/verify.php?token='. $verify_token .'">Verify your Email</a>
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.