Why does @ disappear by clicking the link

Posted on

Question :

I create a link for password reset:

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

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


Answer :

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, you would need 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>';

Update : I also adjusted the quotation marks so that the href attribute had the value in double quotation marks. This can also prevent problems in interpreting the value of the browser part.


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

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

Note: Do not forget to enclose href , either with single or double quotation marks.


Leave a Reply

Your email address will not be published. Required fields are marked *