title: Yii2 Advanced email template
body: <p>I'm using Yii2 advanced version. I have configured email configuration in <code>common\config\main-local.php</code> as follows:</p>
  
  <pre><code>'mailer' =&gt; [
              'class' =&gt; 'yii\swiftmailer\Mailer',           
              'viewPath' =&gt; '@common/mail',
              'useFileTransport' =&gt; false,
              'transport' =&gt; [
               'class' =&gt; 'Swift_SmtpTransport',
               'host' =&gt; 'smtp.gmail.com',
               'username' =&gt; 'XXXXX',
               'password' =&gt; 'XXXXXX',
               'port' =&gt; '587',
               'encryption' =&gt; 'tls',
           ],
          ],
  </code></pre>
  
  <p>I have created one email component under <code>common\components\EmailComponent.php</code>
  Which contains code for sending an email :</p>
  
  <pre><code>protected function sendEmail($email, $subject, $message, $options= array()) {
              $email = 'myemail@myemail.com';
             **$emailSend = Yii::$app-&gt;mailer-&gt;compose(['html' =&gt;'layouts/html'],['content' =&gt; $message])**
                      -&gt;setFrom(["myemail@myemail.com"])
                      -&gt;setTo($email)
                      -&gt;setSubject($subject);
          return $emailSend-&gt;send();
      }
  </code></pre>
  
  <p>I have created two layout files under</p>
  
  <p>1) <code>common\mail\layouts\html.php</code></p>
  
  <pre><code>    &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=&lt;?= Yii::$app-&gt;charset ?&gt;" /&gt;
      &lt;/head&gt;
      &lt;body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"&gt;
          &lt;table id="Table_01" border="0" cellpadding="0" cellspacing="0" align="center" height="411" width="600" style="font-family:arial; font-size:14px;"&gt;
              &lt;tbody&gt;      
  &lt;tr&gt;
                  **&lt;td colspan="4" style="border-bottom:1px solid #bc2744; height:1px"&gt;First&lt;/td&gt;**
              &lt;/tr&gt;  
                  &lt;tr&gt;
                      &lt;td colspan="2"&gt;
                         &lt;?php
                         echo $content;                   
                         ?&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  **&lt;td colspan="4" style="border-bottom:1px solid #bc2744; height:1px"&gt;Second&lt;/td&gt;**
              &lt;/tbody&gt;
          &lt;/table&gt;   
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>2) <code>common\mail\layouts\text.php</code></p>
  
  <pre><code>&lt;?php $this-&gt;beginPage() ?&gt;
  &lt;?php $this-&gt;beginBody() ?&gt;
  &lt;?=  $content; ?&gt;
  &lt;?php $this-&gt;endBody() ?&gt;
  &lt;?php $this-&gt;endPage() ?&gt;
  </code></pre>
  
  <p>When I fire an email from any section then I get an emails but it shows "First" text  Two times Then My content will come and then again it shows "Second" text Two times from email html.php file. 
  I don't know why this is happening, I have searched a lot but no luck.</p>