PHP e-mail delivery verify function

Source: Internet
Author: User
PHP Mail Send verification function

First step: Build a Database

Copy and paste the following database into a Notepad, and then create a new database in phpMyAdmin and import the following data.

– The structure of the table ' Registered_members '

CREATE TABLE ' Registered_members ' (
' ID ' int (4) not NULL auto_increment,
' Name ' varchar (+) not NULL default ",
' Email ' varchar (+) not NULL default ",
' Password ' varchar (+) not NULL default ",
' Country ' varchar (+) not NULL default ",
PRIMARY KEY? (' ID ')
) Engine=myisam DEFAULT charset=latin1 auto_increment=1;


– Export the data in the table ' Registered_members '

– ——————————————————–

– The structure of the table ' temp_members_db '

CREATE TABLE ' temp_members_db ' (
' Confirm_code ' varchar (+) not NULL default ",
' Name ' varchar (+) not NULL default ",
' Email ' varchar (+) not NULL default ",
' Password ' varchar (not NULL default "),
' Country ' varchar (+) not NULL default "
) Engine=myisam DEFAULT charset=latin1;


– Export the data in the table ' temp_members_db '

Step two: Establish a database connection

Please copy the following code into your text editor and name it: config.php

$host = "Hostname"; Host Name
$username = "username"; Mysql username
$password = "password"; Mysql Password
$db _name= "DB name"; Database Name

Connect to server and select database.
Mysql_connect ("$host", "$username", "$password") or Die ("Cannot connect to server");
mysql_select_db ("$db _name") or Die ("Cannot select db");

?>

Step Three: Register page
Please copy the following code into your text editor and name it: signup.php







?

Fourth step: Data insertion into data and mail sending

Please copy the following code into your text editor and name it: signup_ac.php

Include (' config.php ');

Table name
$tbl _name=temp_members_db;

Random Confirmation Code
$confirm _CODE=MD5 (Uniqid (rand ()));

Values sent from form
$name =$_post[' name '];
$email =$_post[' email '];
$country =$_post[' country '];

Insert data into Database
$sql = "INSERT into $tbl _name (confirm_code, name, email, password, country) VALUES (' $confirm _code ', ' $name ', ' $email ', ' $ Password ', ' $country ') ";
$result =mysql_query ($sql);

If suceesfully inserted data into database, send confirmation link to email
if ($result) {

—————-SEND MAIL FORM —————-

Send e-mail to ...
$to = $email;

Your subject
$subject = "Your confirmation link Here";

From
$header = "From:your name ";

Your message
$message = "Your comfirmation link \ r \ n";
$message. = "Click on the" link to activate your account \ r \ n ";
$message. = "http://www.yourweb.com/confirmation.php?passkey= $confirm _code";

Send email
$sentmail = Mail ($to, $subject, $message, $header);

}

If not found
else {
echo "Not found your e-mail in our database";
}

If your email succesfully sent
if ($sentmail) {
echo "Your confirmation Link has Been Sent to Your Email Address.";
}
else {
echo "Cannot send confirmation link to your e-mail address";
}

?>

Fifth step: Verify

Please copy the following code into your text editor and name it: confirmation.php

Include (' config.php ');

passkey that got from link
$passkey =$_get[' passkey '];

$tbl _name1= "temp_members_db";

Retrieve data from table where row, match this passkey
$sql 1= "SELECT * from $tbl _name1 WHERE confirm_code = ' $passkey '";
$result 1=mysql_query ($sql 1);

If successfully queried
if ($result 1) {

Count How many row have this passkey
$count =mysql_num_rows ($result 1);

If found this passkey on our database, the Retrieve data from table "temp_members_db"
if ($count ==1) {

$rows =mysql_fetch_array ($result 1);
$name = $rows [' name '];
$email = $rows [' email '];
$password = $rows [' Password '];
$country = $rows [' Country '];

$tbl _name2= "Registered_members";

Insert data that retrieves from "temp_members_db" into table "Registered_members"
$sql 2= "INSERT into $tbl _name2 (name, email, password, country) VALUES (' $name ', ' $email ', ' $password ', ' $country ');
$result 2=mysql_query ($sql 2);
}

If not found passkey, display message "Wrong confirmation code"
else {
echo "Wrong confirmation code";
}

If successfully moved data from table ' temp_members_db ' to table ' registered_members ' displays message ' Your account have been activated "and don t forget to delete confirmation code from table" temp_members_db "
if ($result 2) {

echo "Your account had been activated";

Delete information of this user from table "temp_members_db" that is have this passkey
$sql 3= "DELETE from $tbl _name1 WHERE confirm_code = ' $passkey '";
$result 3=mysql_query ($sql 3);

}

}
?>

Attention:

If you don't have a mailbox server, you'll see something like the following:

Warning: Mail () [Function.mail]: Failed to connect to mailserver at "localhost" port, verify your "SMTP" and " Smtp_port "setting in php.ini or use Ini_set () inE:\wamp\www\mailverification\signup_ac.php? the
Cannot send confirmation link to your e-mail address

Don't panic, it means your data has been written into the database.

You can use the following methods to pass validation:

First copy this URL to your browser: http://www. your website . com/confirmation.php?passkey=

Then to your database inside the confirm_code copy paste after passkey=, and enter, will appear prompt: Your account had been activated!

Congratulations! Your email verification system is complete! If there is any problem, please feel free to leave a message, back to the fastest speed to solve your problem. Because of the time relationship, English will not be translated.

Original source : http://blog.jiexi-it.com/?p=72

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.