

This post will show you how to use PHP and MySQL for OTP (One-Time Password) verification after user registration. Email otp verification in php is an important step in user authentication that verifies that the registered email or phone number matches that of the real user.
To get started, create a database and a table to record OTP and user information.
CREATE DATABASE otp_verification;
USE otp_verification;
CREATE TABLE registerform (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
otp VARCHAR(6) NOT NULL,
status ENUM('Pending', 'Verified') DEFAULT 'Pending'
);
Create an HTML form that people can fill out with their password, email address, and name to register.
0) {
echo "Email already exists
";
} else {
$sql = "INSERT INTO registerform (name, email, password, otp) VALUES ('$name', '$email', '$password', '$otp')";
if (mysqli_query($conn, $sql)) {
$_SESSION['email'] = $email;
mail($email, "OTP Verification", "Your OTP is: $otp", "From: noreply@yourdomain.com");
header("Location: verify_otp.php");
} else {
echo "Registration failed
";
}
}
}
?>
After registration users are sent to an OTP verification page.
OTP Verified Successfully";
session_destroy();
} else {
echo "Invalid OTP
";
}
}
?>
This tutorial shows how to implement an OTP verification system in PHP and MySQL. It ensures secure authentication of users during registration. You can extend this system by integrating SMS OTP services for mobile verification using email OTP verification in php.