Send Email Verification And OTP Through PHPMailer

This is the phpMailer explanation of the Login Module.

Installation

Method 1 : Composer

You can use Composer or simply Download the Release. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

composer require phpmailer/phpmailer

If you are downloaded PHPMailer through composer, then remember to include the autoloader to your PHP coding.

require_once 'vendor/autoload.php';

Method 2: Download

Alternatively, if you're not using composer, download the PHPMailer from here and put into path directories specified in your PHP configuration

Finally, Not matter your are using composer or download instead, it is compulsory to include the PHPMailer into you PHP coding

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

Generate Email Verification

Create email verification via PHPMailer for account registration

At registeration.php

Replace the Username and Password to your [Email Username] and [App Password].

The way to generate app password refer to generate app password

At verify.php

verify the code attached at url and find the correct user.

At login.php

Check verification result to ensure email has been verified

\

Forgot Password OTP

Generate OTP code when user forgot password

At forgot.php

Generate random OTP code and store into database.

At otp_confirm.php

Confirm OTP by retrieving and comparing OTP code stored in database and code entered by user with otp_confirm.php

Last updated