Page 1 of 1

How to send user confirmation email after registration in PHP?

Posted: Tue Sep 13, 2016 10:53 am
by Thandava Krishna TK
Hello,
One of my friends developed a small site using PHP code, and now he wants to add the login procedure to the site as well.We all know that we receive a confirmation email after getting registered on the site.He wants to add the same procedure to his site.Let me know the possible ways.

Thanks in advance

Re: How to send user confirmation email after registration in PHP?

Posted: Tue Sep 13, 2016 11:30 am
by abhishek
We can send user confirmation email with the help of mail function.

You can get user's email id from registration.

Define user's mail in a variable, like $to=$_POST['email']; Here email is field name of registration form and POST is the method of form submit.

Define your message and subject. You can define your message with HTML tag.

$message= "Thank you for registration. ";
$subject = "Thank you for registration with 24x7.";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

Always define $headers for mail,

if want to send attachment use below header

$random_hash = md5(date('r', time()));
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";


mail($to, $subject , $message, $headers );

Re: How to send user confirmation email after registration in PHP?

Posted: Tue Sep 13, 2016 12:30 pm
by Thandava Krishna TK
Thank you bro,i will let you know if any prob !!.

Re: How to send user confirmation email after registration in PHP?

Posted: Tue Sep 13, 2016 6:28 pm
by sklohar
Thandava Krishna TK wrote:Hello,
One of my friends developed a small site using PHP code, and now he wants to add the login procedure to the site as well.We all know that we receive a confirmation email after getting registered on the site.He wants to add the same procedure to his site.Let me know the possible ways.

Thanks in advance


Hi Krishna,

Developing user confirmation email can be done using "email" function provided in php language. Before proceeding I will consider that you have created table in database which contain username, password and hashkey [optional] for more security you can implement hash key too.

Using simple query you will be able to extract email id, password, hash key from database to form URL in email, which can be used for confirmation.

Code: Select all

$to      = $email; // Email fetched from database
$subject = 'Signup | Verification'; // Specify subject for your email

//Below is message created to display user.
$message = '
 
Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
 
------------------------
Username: '.$name.'
Password: '.$password.'
------------------------
 
Please click this link to activate your account:
http://www.yourwebsite.com/verify.php?email='.$email.'&hash='.$hash.'
 
';
                     
$headers = 'From:noreply@yourwebsite.com' . "\r\n"; // Remember to specify header.
mail($to, $subject, $message, $headers); // this is the function with appropriate parameter  to send email to registered user.


In above code $name, $password, $email, $hash are retrieve from database.
Hash key is optional which can be created while entering user detail in database and same can be store in one of the field of user_detail table to use it in future for verification.

Though you can pass email id in link and verify using that email id, you can also use hash key to make your url complex and difficult to guess for naive user.

Re: How to send user confirmation email after registration in PHP?

Posted: Tue Sep 13, 2016 8:03 pm
by Atish Ranjan
Thanks Abhishek ji, and Shiv for contributing your solutions.

Appreciate it.

Re: How to send user confirmation email after registration in PHP?

Posted: Wed Sep 14, 2016 2:45 am
by Thandava Krishna TK
Thank you all :D for your quick responses :)