Username and Password not accepted in yii2

I have a error with yii2, I can't send emails via yii with a email account. If my password is correct :( This is my code:


'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
            'class'      => 'Swift_SmtpTransport',
            'host'       => '',
            'username'   => '',
            'password'   => 'passwd',
            'port'       => '587',
            'encryption' => 'tls',


Yii::$app -> mailer -> compose()
          -> setFrom('')
          -> setTo('')
          -> setSubject('Test')
          -> setTextBody('Plain text content')
          -> setHtmlBody('It is a test')
          -> send();


It looks like you are using Google SMTP server. Google has a new security check that only allows you to send emails from google apps. If you are using any other you will run into such errors. To fix this you can do as follows:

Use default sendmail function by having

 'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,

I find the first solution more efficient

Change google setting to allow less secure apps

Follow this link to change you gmail settion

I use the following configuration and work right

is pratically equals to yours but with a difference the username is google mail user and not an noyt google app user

    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        // send all mails to a file by default. You have to set
        // 'useFileTransport' to false and configure a transport
        // for the mailer to send real emails.
        //'useFileTransport' => true,
        'useFileTransport' => false,//set this property to false to send mails to real email addresses
        //comment the following array to send mail using php's mail function
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => '',
            'username' => '',
            'password' => 'mypassword',
            'port' => '587',
            'encryption' => 'tls',

hope is useful

Need Your Help

What does x = y mean in python?

python python-2.7

This question has been raised because of a certain example I encountered while reading about actual and formal arguments. Let x and y be 2 non-iterable variables

XML Syntax for Schtasks.exe


I am writing a program in VB.NET which creates highest-privilege scheduled tasks using an XML document and the schtasks.exe command line tool. The problem that I have run into is which XML tag to u...