1

I want to pass an url via email , and when user clicks on the link I want to get his email address? Is this possible in php/javascript? Please advice

  • No it is not possible with PHP or Javascript to just grab the email address. You could pass the email address/unique identifier in URL but this would need to be inside the URL you sent to the users mailbox. – Kitson88 Dec 09 '16 at 15:19
  • Do you want to pass `url via email`, or `email via url`. Its a bit confusing? – Saumya Rastogi Dec 09 '16 at 15:20
  • @SaumyaRastogi : I want to send flyer and when user click on flyer it will goes to a page and i want to display clicked recipient's email on that page –  Dec 09 '16 at 15:23
  • @Kitson88 : I want to send flyer and when user click on flyer it will goes to a page and i want to display clicked recipient's email on that page –  Dec 09 '16 at 15:23
  • It means you want to send `email via url`. Am I right? – Saumya Rastogi Dec 09 '16 at 15:24
  • 2
    If you are emailing this flyer to the user then you must already have the email so just code the `` like this `Click here to sign up!` – MonkeyZeus Dec 09 '16 at 15:25
  • As stated, you would need to have the data in the URL. You can then fetch the data by using `$_GET['']` via PHP. – Kitson88 Dec 09 '16 at 15:26

2 Answers2

3

You can always attach URL parameters to the links you embed into the emails you are sending.

Since you know the user's email address at the point where you are generating the email -- otherwise you couldn't send it in the first place -- you can do exactly that.

For example, instead of linking to http://example.com, append the user's email address to the link: http://example.com?user=foo@gmail.com.

When the user opens your page, look for this parameter and read the email address.


To make it less easy to manipulate, you could also generate unique tokens per user/email/link and append those to the URL instead of the email address. You will have to map the token back to the user record in your application logic later.


Note that this should not be used as an authentication mechanism, as any other user can simply add the parameter manually and circumvent it that way.

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
  • You could use a nonce token. There are plenty of tools available for php to manage them. A nonce is a generated random token that can only be used once. You would have list of email addresses matched to nonce tokens. Obviously when that token is returned, you already know the email address associated with it. The nonce in this case, would function as a valid authentication method. [Click for php and nonce usage](http://stackoverflow.com/questions/4145531/how-to-create-and-use-nonces) – zipzit Dec 09 '16 at 15:42
2

You can pass email via url by passing the email as GET Params to php server like this:

http://example.com?email=myemail@example.com

and when user click the link, get it in your PHP & retrieve it by using $_GET variable like this:

$email = $_GET['email'];

Hope this helps!

Saumya Rastogi
  • 13,159
  • 5
  • 42
  • 45