Answer the question
In order to leave comments, you need to log in
What is the best way to insert a link in an email?
Hey! I'm making an API. There is a standard registration functionality:
1. Registration request
2. Registration confirmation
I send letters through the SignUpConfirmTokenSender service .
public function send(Email $email, string $token): void
{
$message = (new Swift_Message($this->translator->trans('Sig Up Confirmation', [], 'mail')))
->setTo($email->getValue())
->setBody($this->twig->render('mail/user/signup.html.twig', ['token' => $token]), 'text/html');
if (!$this->mailer->send($message)) {
throw new RuntimeException($this->translator->trans('Unable to send message.', [], 'error'));
}
}
{% extends 'mail.html.twig' %}
{% block body %}
<p>Password Reset Link:</p>
{% set url = url('auth.reset.reset', {'token': token}) %}
<p><a href="{{ url }}">{{ url }}</a></p>
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Generate a link on the server, let's say the user's id in bcrypt format cut in half, and immediately enter this code into the database, and the link status can be a separate field, or separated by a colon.
dsf23$fd:false/true
Next, create a page to which your link will lead, pass the same encrypted id to the url parameters, if everything is ok, display the confirm button, all sorts of goodies like a smiley and a greeting - if the link is already true, let's say, display your account is already activated, run away from here. as a result, the link should be like this:
my-app.com/dsf23$fd
Then the script takes the link from the url, divides the string into an array by : and as a result you have an array of two elements for the corresponding checks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question