How to send user confirmation email after registration in PHP?

If you don't find any appropriate forum thread to post your question, then post on this thread by creating a new topic.
Thandava Krishna TK
Junior Member
Posts: 59
Joined: Tue Jul 26, 2016 6:08 pm
Location: Guntur,Andhra Pradesh,India
Contact:

How to send user confirmation email after registration in PHP?

Postby Thandava Krishna TK » Tue Sep 13, 2016 10:53 am

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

abhishek
Junior Member
Posts: 1
Joined: Tue Jul 26, 2016 12:04 pm

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

Postby abhishek » Tue Sep 13, 2016 11:30 am

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 );

Thandava Krishna TK
Junior Member
Posts: 59
Joined: Tue Jul 26, 2016 6:08 pm
Location: Guntur,Andhra Pradesh,India
Contact:

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

Postby Thandava Krishna TK » Tue Sep 13, 2016 12:30 pm

Thank you bro,i will let you know if any prob !!.

sklohar
Junior Member
Posts: 6
Joined: Sat Jul 30, 2016 4:07 pm
Contact:

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

Postby sklohar » Tue Sep 13, 2016 6:28 pm

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.

Atish Ranjan
Administrator
Posts: 277
Joined: Sat Jul 23, 2016 12:12 pm
Location: India
Contact:

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

Postby Atish Ranjan » Tue Sep 13, 2016 8:03 pm

Thanks Abhishek ji, and Shiv for contributing your solutions.

Appreciate it.
Atish Ranjan
Administrator

Thandava Krishna TK
Junior Member
Posts: 59
Joined: Tue Jul 26, 2016 6:08 pm
Location: Guntur,Andhra Pradesh,India
Contact:

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

Postby Thandava Krishna TK » Wed Sep 14, 2016 2:45 am

Thank you all :D for your quick responses :)


Return to “Miscellaneous”

Who is online

Users browsing this forum: No registered users and 1 guest