【问题标题】:PHP confirmation email link is takes me to the wrong pagePHP 确认电子邮件链接将我带到错误的页面
【发布时间】:2012-12-26 15:40:11
【问题描述】:

我有一个 php 脚本 :) 基本上,用户注册会收到一封电子邮件并单击激活链接。当他们点击激活链接时,它会将他们带到 activate.php 页面,一切都完成了。 他们收到的电子邮件中的链接问题看起来像

您好用户名,现在这是您的登录信息:

用户名:computing
密码:computing

下一步是点击此链接激活您的帐户:点击这里

您可以在上面的最后一行中看到,该网站的名称已连接到该链接应该将它们带到的 activate.php 页面。所以我猜我的错误还不错,我只是缺少正斜杠或类似的东西。 无论如何,我认为问题来自下面的代码。我尽量保持代码简短。

<?

// send email
$myname = $contact_name;
$myemail = $contact_email;

$contactname = $signup[fname];
$contactemail = $signup[email];
$message = "Hello ".$signup[fname].",<BR>".
"Get ready to start getting the hits you deserve. Now here is your login info:<BR>     <BR>".
"username: ".$signup[username]."<BR>".
"password: ".$signup[password]."<BR><BR>".
"<B>The next step is to click on this link to activate your account:<a href=".$siteUrl."activate.php?username=".$signup[username].">CLICK HERE</a></b>";
$subject = $title;

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$myname." <".$myemail.">\r\n";
$headers .= "To: ".$contactemail." <".$contactemail.">\r\n";
$headers .= "Reply-To: ".$myname." <".$myemail.">\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: Just My Server";

mail($contactemail, $subject, $message, $headers);
$signup[username] = "";
?>

如果有人能对此有所了解,那就太好了。以为我会提到我正在使用 PHP 5.3 我认为我自己的问题来自 href=".$siteUrl."activate.php?username=".$signup[username].">点击这里"; $主题 = $标题;

但我需要知道的人提供一些有效的输入 :)。

【问题讨论】:

  • 为了安全起见,您是否对密码进行哈希处理,您也可能不想发送明文密码。您可能想要添加令牌激活,例如:example.com/activate.php/?token=dhwudf983nsdfwuen&user=nwenwsli2nf82ndj 并检查用户和令牌,然后您就会知道那是实际点击链接的用户
  • 感谢您的意见,稍后我将为此创建一个单独的线程。因为就像你说的安全方面很蹩脚。因此,您可以随意加入。问候尼日。

标签: php email activation


【解决方案1】:

消息中的“a”和“href”之间需要一个空格。

此外,所有现代电子邮件客户端都会自动将 URL 转换为链接,因此可能根本不需要使用 href 标记。

【讨论】:

  • 嗨,克里斯,这是我在这里粘贴代码时的错误。 “a”和“href”之间有一个空格,我已经更正了这个让其他人看到。谢谢尼日。
【解决方案2】:

我注意到,当您分配链接时,您使用了 .$siteUrl。你真的设置了那个变量吗?

此外,由于您将来自外部来源(电子邮件托管网站),因此将链接“硬编码”作为您的完整网站地址同样有效。例如:

<a href="http://www.yourwebsite.com/yourdirectories/activate.php?username=".$signup[username].">Click Here</a>

所以你的消息值可能是一个值。

$message = "Hello ".$signup[fname].",<BR>".
"Get ready to start getting the hits you deserve. Now here is your login info:<BR>     <BR>".
"username: ".$signup[username]."<BR>".
"password: ".$signup[password]."<BR><BR>".
"<B>The next step is to click on this link to activate your account:<a href='http://www.yourwebsite.comactivate.php?username=".$signup[username]."'>CLICK HERE</a></b>";

你不应该对双斜线有问题,但如果你有问题,你可以使用:

$message = "Hello ".$signup[fname].",<BR>".
"Get ready to start getting the hits you deserve. Now here is your login info:<BR>     <BR>".
"username: ".$signup[username]."<BR>".
"password: ".$signup[password]."<BR><BR>".
"<B>The next step is to click on this link to activate your account:<a  href='http:/"."/www.yourwebsite.com/activate.php?username=".$signup[username]."'>CLICK HERE</a></b>";

【讨论】:

  • 嗨,Devon,我刚刚尝试了你所说的,但是当我尝试实现这一点时遇到的问题是网址从 IE http:// 开始,只要我执行 2 斜杠我的代码被注释掉。您是否可以使用我上面的代码并实现让我们说最后几行,这样我就可以进行复制和粘贴。干杯尼日
  • 谢谢德文,早上 2.40。我很古怪,在解决这个问题之前拒绝上床睡觉。你修好了。谢谢尼日
  • @user1906671:谢谢,我很乐意提供帮助,请记住将我的答案作为解决方案勾选,以便其他人知道它已得到解答。
【解决方案3】:

因为它在字符串 "s 内,所以您需要转义它们或使用单引号。

这是一个固定版本:

$message = "Hello ".$signup[fname].",<br>".
  "Get ready to start getting the hits you deserve. Now here is your login info:<br>     <br>".
  "username: ".$signup[username]."<br>".
  "password: ".$signup[password]."<br><br>".
  "<b>The next step is to click on this link to activate your account: 
  <a href='".$siteUrl."activate.php?username=".$signup[username].'>CLICK HERE</a></b>";

【讨论】:

  • Philip Whitehouse,感谢您的回复我尝试了您的代码并收到此错误。解析错误:语法错误,第 157 行的 D:\hosting\7560507\html\fast\traffic1\reg.php 中的意外 T_ENCAPSED_AND_WHITESPACE 第 157 行是您提供的最后一行代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-18
  • 1970-01-01
  • 1970-01-01
  • 2011-10-08
  • 1970-01-01
  • 1970-01-01
  • 2013-04-22
相关资源
最近更新 更多