在PHP Mailer中添加一个将被重定向到其他网页的HTML设计按钮?

ecfsfe2w  于 2022-11-21  发布在  PHP
关注(0)|答案(1)|浏览(206)

我想添加一个按钮,当点击时会被重定向到另一个网页。它也有一个令牌,但它说我的令牌不存在。我认为我的按钮的链接在PHP Mailer中的HTML中不起作用。
下面是我的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.';
    }

这是我的verify.php的代码,链接将被重定向到这里。

<?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");
  }

?>
vhmi4jdf

vhmi4jdf1#

你的链接必须是这样的东西!

$email_template    = '
       ...
       ...
       ...
      <a href = "http://localhost/appsys/website/verify.php?token='. $verify_token .'">Verify your Email</a>

相关问题