How to escape ampersand using laravel mail and gmail

Viewed 541

I am using Laravel Mail for sending emails via SendInBlue. It was all working just fine but today I started to face an issue which was not present before.

Issue happens with a link generated in the blade email template.

This is example of code which generates the link:

'link' => env('FRONT_APP').'verification?userid=25&code=12345'

The link is then being sent to Blade email template, and used as follows:

<a href="{{ $link }}">PRESS TO CONTINUE</a>

However, after the email is delivered, the URL is actually: /verification?_se=YW5kcml1cy5rYlyeXMubHRAZ21haWuY39t&userid=25&amp%3Bcode=12345

It seems that problem is with special character encoding of ampersand. However changing it to &amp; changes the URL to the following: /verification?_se=YW5kcml1cy5rYlyeXMubHRAZ21haWuY39t&userid=25&amp%3Bamp%3Bcode=12345

I'm also not sure where this bit _se=YW5kcml1cy5rYlyeXMubHRAZ21haWuY39t comes from. All of this wasn't happening before I started using SendInBlue. I am using my Gmail account for sending emails to test. Any ideas how I could fix this?

3 Answers

To avoid escaping the string in your blade files, use {!! !!} instead of {{ }}

<a href="{!! $link !!}">PRESS TO CONTINUE</a>

There is an important element in your issue: you are sending emails through Sendinblue. As stated in their documentation, Sendinblue updates the href to add their own tracking element so the attribute "_se" is probably added at that time. But it should not be an issue (and it was probably the case before you started analysing this problem).

Regarding the escaping of "&" and in addition to N69S answer, you should first of all define at which step this character is escaped by checking the code generated by your view (simply add a dd statement before calling Sendinblue API). Then you will know if you have to fix your PHP code or if you should instead ask Sendinblue support.

The problem seems to be resolved. It was on Sendinblue side. They introduced a bug when they added the «_se» parameter.

It has affected all links in emails sent between 15 and 16 September.

Related