Sending a confirmation email after registration

I have the code below to send an email to the registered user after completing a registration form
As a next step I would like to add a confirmation link that the user will receive in their email
(http://www.realestateonlinecy.com/regverificationaccount.php/hash=$hash)
the members table has the following fields
id, fname, lname, email, address, city, telephone1, telephone2, username, password, hash

How do I proceed? How do I generate a hash to store it in the database, and how should I implement the address for the verification to my code?
php 
error_reporting(E_ALL);

// SEND MAIL FROM A FORM

// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $str = stripslashes($str);
    $str = trim(preg_replace("/ +/", " ", $str));
    $str = preg_replace('/^ a-zA-Z0-9&+:?_\.\-/', '', $str);
    return $str;
}


// IF THE DATA HAS BEEN POSTED
if (isset($_POST['email']) && !empty($_POST['email']))
{
	// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR TEST
	$to  = clean_string($_POST['email']);
	$from  = "noreply@realestateonlinecy.com";
	$subj  = "RealEstateOnline Registration";

	// CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
	$fname         = clean_string($_POST["fname"]);
	$lname         = clean_string($_POST["lname"]);
	$email         = clean_string($_POST["email"]);
	$address       = clean_string($_POST["address"]);
	$city          = clean_string($_POST["city"]);
	$telephone1    = clean_string($_POST["telephone1"]);
	$telephone2    = clean_string($_POST["telephone2"]);
	$username      = clean_string($_POST["username"]);
	$password1     = clean_string($_POST["password1"]);
	$password2     = clean_string($_POST["password2"]);

	// CONSTRUCT THE MESSAGE
	$content ='';
	$content   .= "Dear $fname $lname,\n\n";
	$content   .= "We would like to welcome you to our member zone\n";
	$content   .= "and thank you for registering to our website\n\n";
	$content   .= "With Regards\n\n";
	$content   .= "Real Estate Online";
	$content   .= "Member Services\n\n";
        
    mail( $to, $subj, $content, "To:$to\r\nFrom: $from\r\n");


	// To Admin
	$to1    = "admin@realestateonlinecy.com";
    $from1  = "noreply@realestateonlinecy.com";
	$subj1  = "RealEstateOnline - Member Registration";

	// CONSTRUCT THE MESSAGE
	$message    = '';
	$message    = "This is an automated message to let you know that\n";
	$message   .= "there is a new registration on the Real Estate Website from $fname $lname\n\n";

	// SEND MAIL
    mail( $to1, $subj1, $message, "To:$to1\r\nFrom: $from1\r\n");

}
?>

Open in new window

dino_angelidesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:

<?php 
error_reporting(E_ALL);

// SEND MAIL FROM A FORM

// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    $str = stripslashes($str);
    $str = trim(preg_replace("/ +/", " ", $str));
    $str = preg_replace('/^ a-zA-Z0-9&+:?_\.\-/', '', $str);
    return $str;
}


// IF THE DATA HAS BEEN POSTED
if (isset($_POST['email']) && !empty($_POST['email']))
{
	// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR TEST
	$to  = clean_string($_POST['email']);
	$from  = "noreply@realestateonlinecy.com";
	$subj  = "RealEstateOnline Registration";
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

	// CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
	$fname         = clean_string($_POST["fname"]);
	$lname         = clean_string($_POST["lname"]);
	$email         = clean_string($_POST["email"]);
	$address       = clean_string($_POST["address"]);
	$city          = clean_string($_POST["city"]);
	$telephone1    = clean_string($_POST["telephone1"]);
	$telephone2    = clean_string($_POST["telephone2"]);
	$username      = clean_string($_POST["username"]);
	$password1     = clean_string($_POST["password1"]);
	$password2     = clean_string($_POST["password2"]);
	$hash=md5("$email $username $password");

	//connect to db here first
	//...
	

	$sql = 	sprintf("INSERT INTO `members`(fname, lname, email, address, city, telephone1, telephone2, username, password, hash) VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"
				,mysql_real_escape_string($fname)
				,mysql_real_escape_string($lname)
				,mysql_real_escape_string($email)
				,mysql_real_escape_string($address)
				,mysql_real_escape_string($city)
				,mysql_real_escape_string($telephone1)
				,mysql_real_escape_string($telephone2)
				,mysql_real_escape_string($username)
				,mysql_real_escape_string($password)
				,mysql_real_escape_string($hash)
			);
	mysql_query($sql) or die(mysql_error());

	// CONSTRUCT THE MESSAGE
	$content ='';
	$content   .= "<pre>Dear $fname $lname,\n\n";
	$content   .= "We would like to welcome you to our member zone\n";
	$content   .= "and thank you for registering to our website\n\n";
	$content   .= "<a href='http://www.realestateonlinecy.com/regverificationaccount.php/hash=$hash'>Description here</a>\n";
	$content   .= "With Regards\n\n";
	$content   .= "Real Estate Online";
	$content   .= "Member Services\n\n</pre>";
        
    mail( $to, $subj, $content, $headers. "To:$to\r\nFrom: $from\r\n");


	// To Admin
	$to1    = "admin@realestateonlinecy.com";
    $from1  = "noreply@realestateonlinecy.com";
	$subj1  = "RealEstateOnline - Member Registration";

	// CONSTRUCT THE MESSAGE
	$message    = '';
	$message    = "This is an automated message to let you know that\n";
	$message   .= "there is a new registration on the Real Estate Website from $fname $lname\n\n";

	// SEND MAIL
    mail( $to1, $subj1, $message, $headers."To:$to1\r\nFrom: $from1\r\n");

}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dino_angelidesAuthor Commented:
i will give that a shot :)
0
hieloCommented:
OK
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

dino_angelidesAuthor Commented:
if i want to store the hash into a hidden variable, what is the value I need to put?
0
hieloCommented:
you don't have a form on what you posted. The hash I created is based on what the user already posted. So upon initial load, there is nothing posted yet so you don't need any hidden field with a hash.
0
dino_angelidesAuthor Commented:
i see ok, thank you I think it worked :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.