通过电子邮件验证链接 [英] validation link via email

查看:217
本文介绍了通过电子邮件验证链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户通过电子邮件地址订阅我的简报时,使用php,我如何通过电子邮件向他们发送激活链接,以确认它是他们的电子邮件地址,而不是假的。

When a user subscribes to my newsletter via their email address, using php, how would I send them an 'Activation Link' via email to confirm it is their email address and not a fake one.

所以现在我有

PHP:

<?php
 $to = "recipient@example.com";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 if (mail($to, $subject, $body)) {
   echo "<p>Message successfully sent!</p>";
  } else {
   echo "<p>Message delivery failed...</p>";
  }
 ?>

我想我会将$ body更改为:

I guess i would change the $body to this:

$body = "Please click the link to activate your email \n
http://www.activationlink.com?";

我如何做到这一点,如果用户点击该链接会将其详细信息添加到Mysql数据库识别他们是合法用户?

How would I make it so that if a user clicked that link it would add their details to the Mysql database recognising they are a legitimate subscriber?

任何帮助或建议赞赏。谢谢

Any help or suggestions appreciated. Thanks

推荐答案

我喜欢做的是:


  • 在注册过程中生成唯一的随机ID

  • Generate a unique, random ID in the registration process

将ID与电子邮件地址一起存储,已确认字段(默认值:否)和数据库表中的任何其他数据

Store the ID along with the E-Mail address, a "confirmed" field (default: "no") and any additional data in a database table

发送电子邮件带有指向要激活唯一ID的URL (例如 domain.com/activate.php?id=102939505595

Send out the E-Mail with an URL pointing to activate the unique ID (e.g. domain.com/activate.php?id=102939505595

激活页面检查是否存在唯一键,并将确认字段更改为(或 1

The activation page checks whether the unique key exists and changes the confirmed field to yes (or 1 or whatever).

此外,可选地,保存确认日期/时间,IP地址和用户代理。

Additionally and optionally, save the confirmation date/time, IP address and user agent.

这篇关于通过电子邮件验证链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆