注册后如何发送邮件
当有人在网站上注册后,通常会向他的邮件帐户发送一封邮件。但是要生成此链接或可以在此链接中放置哪些信息以便可以使用它来激活用户帐户?
After that someone registers in a site, a mail is usually sent to his mail account. But to generate this link or what info can be placed in this link so that it can be used to activate the user account??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以放置任何可以识别有效用户的内容
1- 哈希值
2- 加密字符串
3- Guid
,当用户单击链接时,您可以验证该值。
you can place any thing which can identify a valid user
1- A Hash Value
2- An Encrypted String
3- A Guid
and when user clicks on the link , you can validate the value.
检查这部分代码:
生成代码和电子邮件:
检查激活:
来自 PHPclasses.org 的脚本
Check this part of code:
Generate code and e-mail:
Check activation:
Script from PHPclasses.org
这个想法是有一个只有电子邮件收件人知道的链接。因此,当在您的网站上访问该链接时,您知道有人已阅读您发送的电子邮件并单击该链接,因此您可以假设注册者和阅读该电子邮件的人是同一个人。
因此,您只需要一个不易被猜到的链接。随机选择一些内容(并将其记录在用户的个人资料中)或散列用户名+种子或其他内容。
The idea is to have a link that only the recipient of the email knows. So when that link is visited on your site, you know that someone has read the email you sent and clicked on the link and so you can presume that the person who registered and the person who read the email are the same.
As such, you just need a link that can't be easily guessed. Pick something random (and record it in the user's profile) or hash the user name + a seed, or something.
当用户注册时,您可以使用
uniqid()
创建激活码并存储在数据库中。然后在邮件中提供一个链接,例如:http://....../activate.php?code=[uniqid()]
在
activate.php
中,您可以从数据库读取激活代码并检查它。When user registered, you can use
uniqid()
to create an activate code and stored in database. Then in mail, give a link like:http://....../activate.php?code=[uniqid()]
In
activate.php
, you can read activate code from database and check it.