Sending mail using PHP is very simple. Here I’ll show how we can send the activation mail to a registered using along with the verification key we generated in last post.

    $emailto= "";
    $subject	= "";
    $min_size	= "1";
    $max_size	= "4000";
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .="To:".$emailto."<".$emailto.">\r\n";
    $headers .="From:".$frmname."<".$email.">\r\n";
    $headers 	= "From:";
    $message	= "Registration Successfull!!\n\nThank you for registering with us. \n\nUser name: ". $username . "\nPassword: ". $password ."\n\n Click here for activation.\n".$pass;
   $ok = @mail($emailto, $subject, $message, $headers);
   $msg	= "Registered Successfully";

This will send the recipient with the username and password along with the verification key generated instructing them to click on the link to activate their profile. We will see how to implement the activation page in this post. We also need to understand how to first add the generated key to database.

Actually adding the generated key to database is as easy as any other PHP-MySQL queries. I’ll just give an example here.

$qry = "INSERT INTO users (name, password, email, vkey) VALUES ('$uname', '$passwd', '$email', '$pass');

We’ll be having a field in the ‘users‘ table named ‘status‘ which is by default ‘N’. The purpose of the activate page is set this to ‘Y‘. It is really very easy. Here is the code in the ‘activate.php‘ page.

$verikey = $_GET['verikey'];
 $qry = "UPDATE users SET status = 'Y' WHERE vkey = '$verikey'";