Search code examples
phpsymfonyhtml-emailfosuserbundlemjml

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" class="i3" 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 style="background:#eaeced"><!--- Beginning of the real HTML body that I created --->
<br>
<div style="background-color:#eaeced">
<!--- 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 style="background: #eaeced;">
<div style="background-color:#eaeced;"><!--[if mso | IE]>
    <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;">
        <tr>
            <td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
    <![endif]--><div style="margin:0px auto;max-width:600px;background:#fff;"><table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:#fff;" align="center" border="0"><tbody><tr><td style="text-align:center;vertical-align:middle;direction:ltr;font-size:0px;padding:20px 0px;padding-top:80px;"><!--[if mso | IE]>
                    <table role="presentation" border="0" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:middle;width:600px;">
                    <![endif]--><div class="mj-column-per-100 outlook-group-fix" style="vertical-align:middle;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;"><table role="presentation" cellpadding="0" cellspacing="0" style="vertical-align:middle;" width="100%" border="0"><tbody><tr><td style="word-break:break-word;font-size:0px;padding:10px 25px;padding-top:45px;padding-bottom:20px;padding-right:30px;padding-left:50px;" align="left"><div class="" style="cursor:auto;color:#000;font-family:Poppins,  -apple-system, BlinkMacSystemFont, Helvetica Neue, Arial, sans-serif;font-size:22px;font-weight:700;line-height:2em;text-align:left;">
                                        <span style="font-weight: 700;color:#009EF5; border-bottom: 5px solid #009EF5">Confirmez</span> votre compte LVDF
                                    </div></td></tr><tr><td style="word-break:break-word;font-size:0px;padding:10px 25px;padding-bottom:10px;padding-right:30px;padding-left:50px;" align="left"><div class="" style="cursor:auto;color:#9b9b9b;font-family:Poppins,  -apple-system, BlinkMacSystemFont, Helvetica Neue, Arial, sans-serif;font-size:15px;line-height:22px;text-align:left;">
                                        Hello {{ user.username }}, <br><br>
                                        "Random String here"
                                    </div></td></tr><tr><td style="word-break:break-word;font-size:0px;padding:10px 25px;padding-top:10px;padding-bottom:45px;" align="center"><table role="presentation" cellpadding="0" cellspacing="0" style="border-collapse:separate;" align="center" border="0"><tbody><tr><td style="border:none;border-radius:25px;color:#fff;cursor:auto;padding:12px 50px;" align="center" valign="middle" bgcolor="#009EF5"><a href="{{ confirmationUrl }}" style="text-decoration:none;line-height:100%;background:#009EF5;color:#fff;font-family:Poppins,  -apple-system, BlinkMacSystemFont, Helvetica Neue, Arial, sans-serif;font-size:18px;font-weight:600;text-transform:none;margin:0px;" target="_blank">Confirmer
                                                </a></td></tr></tbody></table></td></tr><tr><td style="word-break:break-word;font-size:0px;padding:10px 25px;padding-bottom:10px;padding-right:30px;padding-left:50px;" align="left"><div class="" style="cursor:auto;color:#9b9b9b;font-family:Poppins,  -apple-system, BlinkMacSystemFont, Helvetica Neue, Arial, sans-serif;font-size:15px;line-height:22px;text-align:left;">
                                        <span style="font-weight: 600; color:#9B9B9B;">the team<br><br> <a href="#" style="display:inline-block;text-decoration:none;color:#9b9b9b;" 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 %}

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.