Link to home
Start Free TrialLog in
Avatar of dino_angelides
dino_angelides

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dino_angelides
dino_angelides

ASKER

i will give that a shot :)
OK
if i want to store the hash into a hidden variable, what is the value I need to put?
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.
i see ok, thank you I think it worked :)