php - FOSUserBundle - Emails rendering issue: <br> tags popping before html body
First of all, the emails work perfectly.
I just have a rendering issue with password_resetting.email.twig and email.html.twig (the one to confirm your email on registration).
I'm just trying to figure out how to get rid of these many<br>
tags that popped right before the HTML code in my template. (see code or screenshot below)
<!--- Taken in my Inbox --->
<div jstcache="3332" jsaction="jsl._" jsan="7.i3,22.jsaction"><!--- Div generated by Google --->
<br> <!--- Beginning of the email body obviously --->
<br>
<u></u>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div ><!--- Beginning of the real HTML body that I created --->
<br>
<div >
<!--- No need to show you the rest of the email --->
Screenshot from inspector in Inbox by Google
I did exactly what was written in the documentation (symfonydoc: FOSUserBundle/emails.html).
I tested with and without :
{% block subject %}Resetting your password{% endblock %}
{% block body_text %}
{% autoescape false %}
Hello {{ user.username }} !
You can reset your password by accessing {{ confirmationUrl }}
Greetings,
the App team
{% endautoescape %}
{% endblock %}
I did my HTML emails using MJML framework. I thought for a while that MJML CLI didn't render it right. So I tested with a basic HTML template picked up randomly on github (https://github.com/leemunroe/responsive-html-email-template)
But the<br>
tags still popped.
Note: there are no extra<br>
tags if I use {% block body_text %} only. It only occurs when I use {% block body_html %}.
Does it come from FOSUserBundle ? Any idea about what I am missing ?
Tested in : - OSX 10.12.4 : Spark client & Mail client, on Chrome in Inbox by Google, Gmail, and Outlook. - iOS10: Spark and Mail
My HTML.twig template with fake data if needed
{% block subject %}Resetting your password{% endblock %}
{% block body_text %}
{% autoescape false %}
Hello {{ user.username }} !
You can reset your password by accessing {{ confirmationUrl }}
Greetings,
the App team
{% endautoescape %}
{% endblock %}
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title></title>
<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
#outlook a { padding: 0; }
.ReadMsgBody { width: 100%; }
.ExternalClass { width: 100%; }
.ExternalClass * { line-height:100%; }
body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
table, td { border-collapse:collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; }
p { display: block; margin: 13px 0; }
</style>
<!--[if !mso]><!-->
<style type="text/css">
@media only screen and (max-width:480px) {
@-ms-viewport { width:320px; }
@viewport { width:320px; }
}
</style>
<!--<![endif]-->
<!--[if mso]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if lte mso 11]>
<style type="text/css">
.outlook-group-fix {
width:100% !important;
}
</style>
<![endif]-->
<!--[if !mso]><!-->
<link href="https://fonts.googleapis.com/css?family=Poppins:400,600,700" rel="stylesheet" type="text/css">
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Poppins:400,600,700);
</style>
<!--<![endif]--><style type="text/css">
@media only screen and (min-width:480px) {
.mj-column-per-100 { width:100%!important; }
}
</style>
</head>
<body >
<div ><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="600" align="center" >
<tr>
<td >
<![endif]--><div ><table role="presentation" cellpadding="0" cellspacing="0" align="center" border="0"><tbody><tr><td ><!--[if mso | IE]>
<table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td >
<![endif]--><div ><table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0"><tbody><tr><td align="left"><div >
<span >Confirmez</span> votre compte LVDF
</div></td></tr><tr><td align="left"><div >
Hello {{ user.username }}, <br><br>
"Random String here"
</div></td></tr><tr><td align="center"><table role="presentation" cellpadding="0" cellspacing="0" align="center" border="0"><tbody><tr><td align="center" valign="middle" bgcolor="#009EF5"><a href="{{ confirmationUrl }}" target="_blank">Confirmer
</a></td></tr></tbody></table></td></tr><tr><td align="left"><div >
<span >the team<br><br> <a href="#" target="_blank"><strong>mysite.io</strong></a></span>
</div></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></td></tr></tbody></table></div><!--[if mso | IE]>
</td></tr></table>
<![endif]--></div>
</body>
</html>
{% endblock %}
Answer
Solution:
Well, of course inside
{% block body_html %}
I don't need the<doctype html>
, nor the<html>
tags.By removing everything (including the
<head>
) but the body, I managed to get rid of these<br>
tags.I lost a few style property generated by MJML in the
<head>
, but the email still displays properly.