Hello when I used php concatenating the code with the link in phpmailer why it's does not working?
Here are the two method that I tried.
This concatenate method does not concatenate the $userverifcationCode with the link but when I copy the link and enter it, it works. But it is a hassle if you are just gonna copy it.
'http://localhost/Bloodlad/user/verificationForgot.php?code='.$user_verificationCode;
This concatenate method works but when I click the link it is echoing invalid code.
'http://localhost/Bloodlad/user/verificationForgot.php?code='.trim($user_verificationCode);
Method 1 verification code: http://localhost/Bloodlad/user/verificationForgot.php?code= xGLNJM
Method 2 verification code: http://localhost/Bloodlad/user/verificationForgot.php?code=SN6Wqq
Method1&2 Picture This is the code for verifying the code.
$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';
}
the $code is the verification code. It is located after the verificatonForgot.php?=code.
$mail->Body = 'http://localhost/Bloodlad/user/verificationForgot.php?code='.$user_verificationCode;
The PHP version I'm using is PHP 7.4.23 / PHP 7.4.23
CodePudding user response:
Encode that part of the URL correctly, like:
$mail->Body = 'http://localhost/Bloodlad/user/verificationForgot.php?code='.rawurlencode($user_verificationCode);