简体   繁体   English

如何在PHP中创建确认电子邮件?

[英]How do I create a confirmation email in PHP?

I was asked by a person to create a php code, which is a part of a larger ERP software development project, so that he can test my skills. 一个人要求我创建一个php代码,这是一个较大的ERP软件开发项目的一部分,以便他可以测试我的技能。 The code regarding a simple user authentication once the user registers through a form , by putting name, date of birth ,email.(which I have already done through html). 一旦用户通过表单注册,然后输入姓名,出生日期,电子邮件(我已经通过html完成),有关简单用户身份验证的代码。

The action property of the html form, is a php file which consists of php code to get the posted inputs in the form, generate a verification link, and send it to the user via his/her email which he/she has already given. html表单的action属性是一个php文件,由php代码组成,用于获取表单中发布的输入内容,生成验证链接,并通过他/她已经提供的电子邮件将其发送给用户。

I have two basic questions or problems: 我有两个基本问题或问题:

  1. How can this verification link be created? 如何创建此验证链接?
  2. Once the user clicks on this type of a link how does PHP know that they did so? 一旦用户单击这种类型的链接,PHP怎么知道他们这样做了?

I don't think that there is any concept of event-driven programming in PHP. 我认为PHP中没有任何事件驱动的编程概念。 In that case, how does PHP handle that click and give a "conformational success message"? 在这种情况下,PHP如何处理该单击并给出“构想成功消息”? Is a MySQL database required or is there another easier way? 是需要MySQL数据库还是还有另一种更简单的方法?

When you create the user, you are also going to generate a random string for that user. 创建用户时,还将为该用户生成一个随机字符串。 This is their authorization code. 这是他们的授权码。 You will store it with the user's data in your database. 您会将其与用户数据一起存储在数据库中。

Then you are going to make your authorize page (ex., authorize.php). 然后,您将创建您的授权页面(例如,authorize.php)。 It will take a $_GET parameter of 'code', or whatever else you want (ex., authorize.php?code=theHashYouCreated ). 它将使用$ _GET参数为'code'或您想要的其他任何参数(例如, authorize.php?code=theHashYouCreated )。 This page's code will look something like this: 该页面的代码如下所示:

if(!empty($_GET['code']))
{
  /*
   * Get the data from the database by the provided code. 
   * If a result is returned, then remove the authorization 
   * code from the user's record. If no user is found, then 
   * return an error.
   */
}
else
{
  //No code was provided, so we should error.
}

Now, when the user tries to login you also want to check to see if their authorization code is set in the database. 现在,当用户尝试登录时,您还想检查一下数据库中是否设置了他们的授权码。 If it is, then they have not validated their e-mail address yet. 如果是,则他们还没有验证其电子邮件地址。 If it isn't, then they have validated it. 如果不是,则他们已经对其进行了验证。

Here's a nice tutorial that should help you create a confirmation email: 这是一个很好的教程,可以帮助您创建确认电子邮件:

http://www.learnphponline.com/scripts/email-activation-for-php-forms http://www.learnphponline.com/scripts/email-activation-for-php-forms

It involves creating a randomly generated activation key, that will initially be stored in the database. 它涉及创建随机生成的激活密钥,该激活密钥最初将存储在数据库中。 The key should be emailed to the user in the form of a GET parameter in a link. 密钥应以链接中GET参数的形式通过电子邮件发送给用户。

Once the link is clicked, the submitted GET parameter is checked with the value in the database. 单击链接后,将使用数据库中的值检查提交的GET参数。

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

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