首页 > 解决方案 > 与链接连接时出现连接无法正常工作的问题

问题描述

您好,当我使用 php 将代码与 phpmailer 中的链接连接起来时,为什么它不起作用?

这是我尝试过的两种方法。

这种连接方法不会将 $userverifcationCode 与链接连接,但是当我复制链接并输入它时,它可以工作。但是,如果你只是要复制它,那就很麻烦了。

'http://localhost/Bloodlad/user/verificationForgot.php?code='.$user_verificationCode;

这种连接方法有效,但是当我单击链接时,它正在回显无效代码。

'http://localhost/Bloodlad/user/verificationForgot.php?code='.trim($user_verificationCode);

方法一验证码:http://localhost/Bloodlad/user/verificationForgot.php?code=xGLNJM

方法二验证码:http://localhost/Bloodlad/user/verificationForgot.php?code=SN6Wqq

Method1&2 图片 这是验证代码的代码。

$code = $_GET['code'];

    $sql="SELECT * FROM users WHERE user_verificationCode=?";
      $stmt=$conn->prepare($sql);
      $stmt->bind_param("s", $code);
      $stmt->execute();
      $result=$stmt->get_result();
      $row=$result->fetch_assoc();
      $count=$result->num_rows;
      if($count > 0){
        $user_isVerified='Yes';
        $user_verificationCode="";
        $sql="UPDATE users SET user_isVerified=?, user_verificationCode=? WHERE user_verificationCode=?";
        $stmt=$conn->prepare($sql);
        $stmt->bind_param("sss", $user_isVerified, $user_verificationCode, $code);
        if($stmt->execute()){
          echo 'You have successfuly verified your account <br>';
          echo '<a href="login.php">Click this link to login</a>';
        }
      }else{
        echo 'Invalid verification code';
      }

$code 是验证码。它位于verificatonForgot.php?=code 之后。

$mail->Body = 'http://localhost/Bloodlad/user/verificationForgot.php?code='.$user_verificationCode;

我使用的 PHP 版本是 PHP 7.4.23 / PHP 7.4.23

标签: php

解决方案


正确编码 URL 的该部分,例如:

$mail->Body = 'http://localhost/Bloodlad/user/verificationForgot.php?code='.rawurlencode($user_verificationCode);

推荐阅读