Why @ disappears by clicking on the link

Asked

Viewed 103 times

3

I create a password reset link:

$mail_message   .= "<a href=$url_sender/redefinir-senha?email=$email_sender&identifier=$identifier_sender&code=$confirmation_code>
    Clique aqui para redefinir sua senha.
</a>";

But by clicking on the link received in the email, the arroba( @ ) disappears. I noticed that this error happens only in Gmail.

2 answers

4


URL parameters must be encoded so that the special characters do not interfere with the way the URL is interpreted.

In the case of PHP, it would be necessary to use a function such as urlencode in each parameter passed.

For example:

$mail_message .= '<a href="'.$url_sender.'/redefinir-senha?'.
    'email=' . urlencode($email_sender) . 
    '&identifier=' . urlencode($identifier_sender) . 
    '&code=' . urlencode($confirmation_code) . 
    '">Clique aqui para redefinir sua senha.</a>';

Updating: also adjusted the quotes so that the attribute href had the value in double quotes. This can also avoid problems interpreting the value of the browser part.

  • It seems that it needs a revision of the quotation marks. And also: the variable will not be recognized in single quotation marks.

  • @brasofilo There are no variables between single quotes. See that I extract everything out and I’m using concatenation. And I just looked again and I didn’t find any quote "imbalance".

  • 2

    I took the liberty of correcting, before I was with the problems cited by @brasofilo

  • @Jader Okay, thank you.

4

Another alternative is to use the function http_build_query as in ex. below:

$mail_message   .= '<a href="' . $url_sender . '/redefinir-senha?' .
http_build_query(array(
   'email' => $email_sender,
   'identifier' => $identifier_sender,
   'code' => $confirmation_code)) . '">Clique aqui para redefinir sua senha.</a>';

Note: Do not forget to enclose the href, either with single or double quotes.

  • 1

    Great suggestion!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.