How To Send Verification Link When A New User Register

How to Send Verification link when a new user register image

We are going to build a nice PHP sign-up script where a user can create an account to gain access to the "members only section" of a website.

After the user creates their account, the account will then be locked until the user clicks a verification link that they'll receive in their email inbox.

// REGISTER USER
if (isset($_POST['register_btn'])) {
	// receive all input values from the form
	$firstname = esc($_POST['firstname']);
	$lastname = esc($_POST['lastname']);
	$genders = esc($_POST["gender"]);
	$username = esc($_POST['username']);
	$email = esc($_POST['email']);
	$password_1 = esc($_POST['password_1']);
	$password_2 = esc($_POST['password_2']);
	// form validation: ensure that the form is correctly filled
	if (empty($firstname)) {
		array_push($errors, "Uhmm...You missed your First Name");
	}
	if (empty($lastname)) {
		array_push($errors, "Uhmm...You missed your Last Name");
	}
	if (empty($username)) {
		array_push($errors, "Uhmm...We gonna need your username");
	}
	if (empty($email)) {
		array_push($errors, "Oops.. Email is missing");
	}

	if (empty($password_1)) {
		array_push($errors, "uh-oh you forgot the password");
	}
	if ($password_1 != $password_2) {
		array_push($errors, "The two passwords do not match");
	}


	// Ensure that no user is registered twice. 
	// the email and usernames should be unique
	$user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
	$result = mysqli_query($conn, $user_check_query);
	$user = mysqli_fetch_assoc($result);
	if ($user) { // if user exists
		if ($user['username'] === $username) {
			array_push($errors, "Username already exists");
		}
		if ($user['email'] === $email) {
			array_push($errors, "Email already exists");
		}
	}
	// register user if there are no errors in the form
	if (count($errors) == 0) {
		$password = md5($password_1); //encrypt the password before saving in the database
		$vkey = md5(time().$username);
		$cenvertedTime = date('Y-m-d', strtotime(' + 5 days'));
		$query = "INSERT INTO users (firstname, lastname, gender, username, email, password, vkey, token_expire, created_at, updated_at) 
		VALUES('$firstname', '$lastname', '$genders', '$username', '$email', '$password', '$vkey', '$cenvertedTime', now(), now())
		";
		$resultset = mysqli_query($conn, $query);

		$inserted_id = mysqli_insert_id($conn);
		$user_check = "SELECT token_expire FROM users WHERE id='$inserted_id' LIMIT 1";
		$result = mysqli_query($conn, $user_check);
		$date = mysqli_fetch_assoc($result);
		$created_at = $date['token_expire'];
		$created_at = date("F j, Y ", strtotime($created_at));

		if ($resultset) {
			$auto = date(Y);
			$to = $email;
			$sent_date = date("F j, Y ");
			$subject = 'Please confirm your email address';
			$message = " < !DOCTYPE html > < html lang = 'en' > < head > < meta charset = 'UTF-8' >
				< meta charset = 'iso-8859-1' >
				< meta name = 'viewport'
			content = 'width=device-width, initial-scale=1.0' >
				< link rel = 'shortcut icon'
			href = ' .BASE_URL . '
			assets / image / slide1.png ' type='
			image / x - icon ' /> < link rel = '
			stylesheet '
			href = ' .BASE_URL . '
			password - recovery / main.css '>           		    < title > Reset Your Password | G3 tech < /title> < /head> < body > < div style = '
			background - color: rgba(44, 62, 80, 0.8);
			max - width: 100 % ;
			height: 80 px;
			'> < a href = '
			https: //www.g3techdesign.com/channel.php' >
				< img src = 'https://www.g3techdesign.com/assets/image/mobileg3tech.png'
			max - width = '100%'
			height = '80px' >
				< /a> < /div > < div style = '		   
			max - width: 100 % ;
			min - height: 100 % ;
			font - size: 20 px;
			border: 2 px solid rgba(44, 62, 80, 0.8);
			color: #a4c9fe!important;
			background - color: black!important;
			padding: 1 px 10 px 10 px 10 px;
			'> < p > Dear < b > < u > ".$firstname." < /u> <u>".$lastname."</u > < /b>,</p > < p > Welcome to G3Tech, and we would like to take an opportunity to thank you
			for taking the time to create an online account with us!

				We need you to verify your identity by the following simple steps: < p / >

				< p > Step 1: Clik the button below to activate your account. < /p> < center > < a href = \"https:/ / www.g3techdesign.com / login.php ? vkey = ".$vkey.
			"\" 
			style = 'background: #EDBD11;
			color: white;
			cursor: pointer;
			padding: 10 px 20 px;
			margin: 8 px 0;
			border: none;
			opacity: 0.9;
			'>Activate  Account</a></center> < p > If the above button will not work properly you may copy the following URL and paste in your favorite browser.Here is a link: < br / >
			https: //www.g3techdesign.com/login.php?vkey=" . $vkey . "</p>

				< p > Step 2: Login with your email / user name and password. < /p>

			< p > Step 3: Access your account and resource you would like. < /p>

			< p > Upon completing these steps, you 'll have full access to your account portal and customize you profile. Thank you for your interest in G3Tech!</p>

			< p > < font color = 'red' > Note: - < /font> This verification link will be expire on ". $created_at .", then the account you created will deleted automatically. If you believe you have received this email in error, please contact us at info@g3techdesign.com </p >

				< p > Regards, < br / >
				All < a href = 'https://www.g3techdesign.com' > G3Tech < /a> Teams</p >
				< /div>   < p style = 'color:gray;' > This email was sent to: ". $to ."
			on ". $sent_date ." < /p>         < div style = '		              
			position: relative;
			background - color: black; /*#272727;*/
			color: orange;
			text - align: left;
			bottom: -10 px!important;
			padding: 10 px - 10 px 5 px 10 px;
			z - index: 1;
			font - size: 14 px;
			width: 100 % ;
			height: 100 px;
			'>                < h3 > < b > < font color = orange > Copyright & copy;
			". $auto ."
			All Rights Reserved. < /font></b > < /h3>               <a href='https:/ / www.g3techdesign.com / termandprivacy.php ' style='
			float: right;
			'>Terms and Privacy</a>            </div> < /body> < /html>
			";
			$headers = "MIME-Version: 1.0".
			"\r\n";
			$headers. = "Content-type:text/html;charset=UTF-8".
			"\r\n";
			$headers. = 'From: Do-Not-Reply noreply@g3techdesign.com'.
			"\r\n";

			mail($to, $subject, $message, $headers);

			$_SESSION['message'] = "<i class='fas fa-check-circle'></i> Thank you for signing up in to our system. We have sent a verification email to the address you provide.<br/><b>".$to.
			"</b> is the email address you provide to us to activate your account.";

			// redirect to public area
			header('location: '.BASE_URL.
				'thankyou.php?email='.$email);
			exit(0);
		} else {
			$_SESSION['message'] = "Something want wrong.";
			// redirect to public area
			header('location: '.BASE_URL.
				'signup.php');
			exit(0);
		}
	}
}

 

Leave a non public comment how to improve it.



Characters Remaining

We are sorry for your bad experiance. Leave a non public comment how to improve it.



Characters Remaining

Related Posts (12)

Getting User Device Location and Updating Database image

Getting User Device Location and Updating Database

Author image
By JOHN Mon Feb 19, 2024 at 12:31 PM (3 months ago)
Updated On Sat Mar 09, 2024 at 07:59 AM (2 months ago)

Read More »
How to create a custom archive page template on your website layout image

How to create a custom archive page template on your website layout

Author image
By JOHN Thu Nov 17, 2022 at 08:00 AM (2 years ago)
Updated On Thu Jan 05, 2023 at 06:24 PM (one year ago)

Read More »
Test the video layout design(Upload and Store video to MySQL Database with PHP) image

Test the video layout design(Upload and Store video to MySQL Database with PHP)

Author image
By JOHN Sat Nov 05, 2022 at 05:15 PM (2 years ago)
Updated On Wed Nov 09, 2022 at 06:39 PM (2 years ago)

Read More »
How to set the expiry period for a reset password link. image

How to set the expiry period for a reset password link.

Author image
By JOHN Mon Oct 10, 2022 at 05:31 AM (2 years ago)
Updated On Tue Nov 08, 2022 at 07:53 PM (2 years ago)

Read More »
Send A verification email when a new user registered  image

Send A verification email when a new user registered

Author image
By JOHN Tue Dec 07, 2021 at 04:53 PM (2 years ago)
Updated On Tue Nov 08, 2022 at 06:58 AM (2 years ago)

DGDFH

Read More »
How to limit the number of login attempts  image

How to limit the number of login attempts

Author image
By JOHN Sat Oct 31, 2020 at 10:19 PM (4 years ago)
Updated On Wed Nov 09, 2022 at 04:38 PM (2 years ago)

It is one of a security mechanism to restrict an authorized user from access the systems and locked the account if it's necessary. In this tutorial we will create a simple login system to demonstrate the implementation using PHP and MySQL. Let's digest it...

Read More »
How to limit the number of login attempt using PHP part 2(PHP functionality) image

How to limit the number of login attempt using PHP part 2(PHP functionality)

Author image
By JOHN Tue Sep 22, 2020 at 06:47 PM (4 years ago)
Updated On Wed Nov 09, 2022 at 05:06 PM (2 years ago)

To protect spam or junk email registration the system have to verify user email by sending a verification link to a  proven email address[] 

Read More »
Download file using PHP image

Download file using PHP

Author image
By MEWDED Wed Sep 02, 2020 at 10:04 AM (4 years ago)
Updated On Sat Nov 12, 2022 at 09:10 AM (2 years ago)

Short explanation 

Read More »
Inactive user enforce to login (SESSION expired) or Limmit the resource image

Inactive user enforce to login (SESSION expired) or Limmit the resource

Author image
By MEWDED Tue Sep 01, 2020 at 04:24 AM (4 years ago)
Updated On Sat Nov 12, 2022 at 09:35 AM (2 years ago)

Quick description

Read More »
How to count page viewers based on the IP Address of the device image

How to count page viewers based on the IP Address of the device

Author image
By MEWDED Thu Aug 27, 2020 at 04:37 PM (4 years ago)
Updated On Sat Nov 12, 2022 at 06:57 PM (2 years ago)

Hi, today we will walk you through how to implement to count the page viewers base on IP address like Youtube or Facebook 

Read More »
Pagination in PHP image

Pagination in PHP

Author image
By MEWDED Fri Aug 14, 2020 at 02:58 PM (4 years ago)
Updated On Fri Nov 04, 2022 at 03:08 PM (2 years ago)

Hi there ????, 

TODAY we are walking ????‍?? together to show you how to implement pagination in PHP

Read More »
Author Title image

Author Title

Author image
By JOHN Mon Jul 13, 2020 at 04:19 AM (4 years ago)
Updated On Fri Nov 04, 2022 at 03:08 PM (2 years ago)

Author description

Read More »

Share this on

Search


Archives

No archives data found yet in 2025.

No archives data found in 2016.

Find Us on Facebook

Subscribe for new updates




Back to Top