简体   繁体   English

向用户发送激活电子邮件

[英]Send activation email to user

How would I do to check if a email actially exists? 如何检查电子邮件是否存在? Cant understand how sites do to send mails with a unique link that the users clicks to validate that he is the owner of email =/ 无法理解网站如何使用用户点击的唯一链接发送邮件以验证他是电子邮件的所有者= /

Make a 2 new columns called activationkey and activated and store some random string, send an email with the activationkey, and update the users activated =1 that match that activation link 创建一个名为activationkey的2个新列并激活并存储一些随机字符串,使用activatekey发送电子邮件,并更新与激活链接匹配的激活用户= 1

register.php?a=activate&key=9cdfb439c7876e703e307864c9167a15

Any better ideas? 有更好的想法吗?

I generally send a link that contains the userid, and the activation key. 我通常会发送一个包含userid和激活密钥的链接。 When they visit my activation script, if I find a match, I activate them. 当他们访问我的激活脚本时,如果找到匹配项,我会激活它们。

When they register, I'll generate maybe 32 chars of upper/lower case alphanumeric characters and set it as the activation key. 当他们注册时,我将生成大约32个大小写字母数字字符并将其设置为激活密钥。 At this point, you can create a field called 'activated,' or you can assume the user is not activated if they have an activation key. 此时,您可以创建一个名为“已激活”的字段,或者您可以假设如果用户具有激活密钥,则不会激活该用户。

uid |        email       | key
------------------------------------------------------------
001 | j.smith@mysite.com | e09141f3f5a17fed6222fc0279b9afdf
------------------------------------------------------------
002 | mary.tyler@abc.com | 
------------------------------------------------------------

When the user accesses the activation script, simply check for the provided key along with the provided id and if a match is found, erase the key from the user record on file (or update your boolean 'activated' field) and open the doors up. 当用户访问激活脚本时,只需检查提供的密钥以及提供的ID,如果找到匹配项,则从文件中的用户记录中删除密钥(或更新您的布尔“激活”字段)并打开门。

If the provided email address doesn't exist, no loss. 如果提供的电子邮件地址不存在,则不会丢失。 You can routinely remove all rows with keys after a month of inactivity. 在一个月不活动后,您可以使用键定期删除所有行。

激活密钥的一种替代方法是仅将生成的密码发送到用户电子邮件,如果用户登录则激活(当然,应该能够将密码更改为他喜欢的密码)。

There's no easy way to check if an email actually exists programatically. 没有简单的方法来检查电子邮件是否以编程方式实际存在。 There are some ways (pinging the mailserver,etc) but none that are proven to work with every mailserver's setup. 有一些方法(ping邮件服务器等)但没有一种方法被证明适用于每个邮件服务器的设置。 Forcing the user to activate their account via a link like you described is the best way to do it. 强制用户通过您描述的链接激活他们的帐户是最好的方法。 Also, you may wish to have some kind of recurring script like a cron-job that removes un-activated members after a certain period of time (which would require another column in your table, timestamp). 此外,您可能希望有一些重复的脚本,如cron-job,在一段时间后删除未激活的成员(这将需要您的表中的另一列,时间戳)。

This is useful because if a user signs up but never activates their account and deletes the email, and you are using their email as an id (just an example), they will never be able to complete the activation. 这很有用,因为如果用户注册但从未激活他们的帐户并删除电子邮件,并且您使用他们的电子邮件作为ID(仅作为示例),他们将永远无法完成激活。 Alternately, if they try to log in you can simply re-send the activation email to that address again. 或者,如果他们尝试登录,您只需再次将激活电子邮件重新发送到该地址即可。

Just make sure in the email you are specifying all the headers (reply-to, from, etc) so your email doesn't get flagged as spam. 只需确保在电子邮件中指定所有标题(回复,来自等),这样您的电子邮件就不会被标记为垃圾邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM