link 包含特殊字符的电子邮件 (php)

link in email with special characters (php)

我的 "Forgot password" 页面向用户发送电子邮件(通过 PHPMailer ver-6.1.1),link 包含他的电子邮件地址。
然后他必须单击 link,这会打开我的 "resetPassword.php" 页面,他可以根据 "resetPassword.php" 页面中包含的电子邮件地址重置密码。 =49=]。

工作正常,但不适用于包含加号 (+) 符号(或任何其他特殊字符)的电子邮件地址。

发送邮件的相关JS代码:

$body="http://localhost/myApp/resetPassword.php?frgt_psw_email=xxxx+1@gmail.com";

这正是收到的电子邮件中的 link。

到目前为止一切顺利。

当点击 link 时,用户被转移到 "resetPassword" 页面,我做的第一件事(用于调试)是:

echo $_GET['frgt_psw_email'];
exit();

我得到的是:xxxx 1@gmail.com。如您所见,加号被替换为 space,因此重置密码功能不起作用。

我尝试用 htmlentities 替换 + 号,但这没有帮助。
我也尝试添加到我的 PHPMailer 参数中:

$mail->CharSet  = 'UTF-8';
$mail->Encoding = 'quoted-printable';

这也没有帮助。

请耐心等待 - 我是 PHP 和 JS 的新手...
谢谢!

一个+是一个保留的URL字符。您需要对查询字符串值进行编码,https://www.php.net/manual/en/function.urlencode.php.

$body="http://localhost/myApp/resetPassword.php?frgt_psw_email=" . urlencode('xxxx+1@gmail.com');