learningbyexample
learningbyexample

Reputation: 1547

How do I create random token so that a mail link can be concatenated to the token

I have one form with a quick poll to answer. What I want to do is send this one form to multiple recipients, that is why I am sending a link by email so that when the recipient accesses the link the recipient can answer the poll and the answers get saved to a table in a database related to their email.

I can't make the link equal to their email address since the recipients would theoretically be able to access another recipients poll that is why I want to add a random token.

I want to be able to link the random token to the mail address.

e.g.
instead of:
www.example.com/poll/[email protected]
I can get:
www.example.com/poll/randomToken

// multiple recipients
$to  = '[email protected]' . ', ';
$to .= '[email protected]';

// subject
$subject = 'Quick Poll';

$lToken = $link.$token;
// message
$message = $lToken;


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n";
$headers .= 'From: me <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";
$headers .= 'Bcc: [email protected]' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);
?>

Upvotes: 1

Views: 69

Answers (1)

Geo Paul
Geo Paul

Reputation: 1817

You can create a Unique Id string using php using the function uniqid http://php.net/manual/en/function.uniqid.php

Create a db table with columns email and unique id so that you have the mapping between them saved in the db.

While sending the link to user send it with

www.example.com/poll/uniqid

and at server find email from uniqeid using sql query.

Upvotes: 2

Related Questions