title: How to use the swiftMailer in Yii2
body: <p>I can't finally understand how to use the swiftMailer extension in Yii2. Judging by that on this subject I didn't find questions, the task is trivial, but up to the end I couldn't understand.</p>
  
  <p>There are examples which don't describe in more detail all cycle of sending the letter or I don't understand something :(</p>
  
  <p><strong>Setup</strong></p>
  
  <pre><code>    return [
      //....
     'components' =&gt; [
      ......
      'mail' =&gt; [
        'class' =&gt; 'yii\swiftmailer\Mailer',
        'transport' =&gt; [
          'class' =&gt; 'Swift_SmtpTransport',
          'host' =&gt; 'localhost',
          'username' =&gt; 'username',
          'password' =&gt; 'password',
          'port' =&gt; '587',
          'encryption' =&gt; 'tls',
        ],
      ],
    ]
  ];
  </code></pre>
  
  <p><strong>Send</strong></p>
  
  <pre><code>Yii::$app-&gt;mail-&gt;compose()
  -&gt;setTo($toEmail)
  -&gt;setFrom([$this-&gt;email =&gt; $this-&gt;name])
  -&gt;setSubject($this-&gt;subject)
  -&gt;setTextBody($this-&gt;body)
  -&gt;send();
  </code></pre>
  
  <p><strong>I want will receive a concrete working example</strong>. Thank you.</p>
  
  <p>P.S. I adjusted domain records MX, DKIM, SPF added.</p>
  
  <p><strong>UPD (some answer)</strong>:</p>
  
  <blockquote>
    <p>E-mail which is passed in "From" field, it is put down by default in the field
    of "Return-path", has to be the <strong>existing address</strong>. Some providers don't
    allow sending mail from nonexistent email addresses.</p>
  </blockquote>