W7Code » PHP » How to send email verification for New Users in PHP

Hello in today class we will learn how to send email verification when a new user registers. After we Created a Login Form and a Register From, now we need confirm the user email by sending an email confirmation.

 

Before we need add two more rows in our database, wich we have created in How to create a Login Form. We will use SQL Language to add this rows:

 

Once that is done we need make some changes in our connection.php file. First we need to save our  hash in our database, this hash will be generated randomly. Than we send a confirmation mail using the php mail function.

(Note: all code is commented if you any doubt contact us)

Our code:

 

 

Now we just need create the file that user will be redirected and he press the url in email, we will call to this file ‘ verify_account.php ‘:

 

This process is almost complete, we just need to change our login settings. Because we only want that user that have active their accounts can login in. For that we just need update one line of code in ‘ connection.php ‘ to:

 

 

Full code of  ‘ connection.php ‘:

 

 

Final result:

 

Download the full code here.

Do you have any doubt? If yes, please comment bellow, so we can explain them.

Leave a Reply