I have a simple name and email form built in Ajax, PHP and mySQL.
The user enters a name, and email address and the fields are saved into a database.
开发者_StackOverflow社区How can I once the name and email have been submitted, send a confirmation email to this user?
I think you're after (double) opt-in. Just to give a basic outline how you can achieve your goal.
- Register user details to your db.
- Store a unique token for every user (every action: new user/lost pw/etc.)
- Store a token lifetime value (the date until token is accepted as valid)
- Use some Mail library for PHP (PHPMailer)
- Send a greeting (validation) message for every new user including their unique tokens
- If user opens the provided link, you could set a flag so user is active from now on.
Note: Since this is just a basic outline i am not mentioned any security pitfalls.
As you haven't provided us much info that's why I'm just giving a imperfect answer here.--
See first in your registration code use bin2hex
on username
to generate activation code because this will make sure that each user have different activation code. And use INSERT INTO
mysql syntax and insert the activation code in a new column named activation_code
or maybe anything as per your needs.
Secondly if registration is successful just send a mail to the email id you just retrieved from the user using mail($to, $subject, $body, $headers)
function where set $to
to your user email id.
Then create a page, just name it as activation.exec.php
where you would get the activation code from the URL
, the URL
has to be sent to the user, and don't forget to include user id
or email id
in that link.
Thirdly add a mysql query to check that the user id you just got from the URL
is in your database or not. And then check that the activation code in the database is similar to the one you just received from the URL
. And if successful redirect him to the Activation Successful page.
I hope this would help you.
精彩评论