PHP mail verification function

Source: Internet
Author: User
PHP mail verification function Step 1: create a database, copy and paste the following database in a notepad, and then create a new database in PHPMyAdmin and import the following data. -Table structure 'registered _ members '-CREATETABLE 'registered _ members' ('id' I PHP mail verification function

Step 1: create a database

Copy and paste the following database in a notepad, and then create a new database in PHPMyAdmin and import the following data.

-Table structure 'registered _ members'
-
Create table 'registered _ members '(
'Id' int (4) not null auto_increment,
'Name' varchar (65) not null default ",
'Email 'varchar (65) not null default ",
'Password' varchar (65) not null default ",
'Country' varchar (65) not null default ",
Primary key? ('Id ')
) ENGINE = MyISAM default charset = latin1 AUTO_INCREMENT = 1;

-
-Export the data 'registered _ members 'in the table'
-
--------------------
-
-Table structure 'temp _ members_db'
-

Create table 'temp _ members_db '(
'Confirm _ code' varchar (65) not null default ",
'Name' varchar (65) not null default ",
'Email 'varchar (65) not null default ",
'Password' varchar (15) not null default ",
'Country' varchar (65) not null default"
) ENGINE = MyISAM default charset = latin1;

-
-Export the table data 'temp _ members_db'
-

Step 2: establish a database connection

Copy the following code to 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 3: Registration page
Copy the following code to your text editor and name it signup. php.







?

Step 4: insert data into data and send emails

Copy the following code to 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 = $ email;

// Your subject
$ Subject = "Your confirmation link here ";

// From
$ Header = "from: your name ";

// Your message
$ Message = "Your Comfirmation link \ r \ n ";
$ Message. = "Click on this 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 email 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 ";
}

?>

Step 5:Verify

Copy the following code to 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 that match this passkey
$ Sql1 = "SELECT * FROM $ tbl_name1 WHERE confirm_code = '$ passkey '";
$ Result1 = mysql_query ($ sql1 );

// If successfully queried
If ($ result1 ){

// Count how many row has this passkey
$ Count = mysql_num_rows ($ result1 );

// If found this passkey in our database, retrieve data from table "temp_members_db"
If ($ count = 1 ){

$ Rows = mysql_fetch_array ($ result1 );
$ 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"
$ Sql2 = "insert into $ tbl_name2 (name, email, password, country) VALUES ('$ name',' $ email ',' $ password', '$ country ') ";
$ Result2 = mysql_query ($ sql2 );
}

// 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 has been activated" and don't forget to delete confirmation code from table "temp_members_db"
If ($ result2 ){

Echo "Your account has been activated ";

// Delete information of this user from table "temp_members_db" that has this passkey
$ Sql3 = "delete from $ tbl_name1 WHERE confirm_code = '$ passkey '";
$ Result3 = mysql_query ($ sql3 );

}

}
?>

Note:

If there is no email server, something like the following will appear:

Warning: Mail () [function. mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php. ini or use ini_set () inE: \ wamp \ www \ mailverification \ signup_ac.php? On line?39
Cannot send Confirmation link to your e-mail address

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

You can use the following methods to pass verification:

Copy the URL to your browser: http: // www.Your website. Com/confirmation. php? Passkey =

Copy and paste confirm_code in Your database after passkey =, and press Enter. the following message is displayed: Your account has been activated!

Congratulations! Your email verification system is complete! If you have any questions, please feel free to leave a message and try again to solve your problem as quickly as possible. Due to the time relationship, English will not be translated.

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.