yii2 mail goes into spam folder of gmail,yahoo etc

Hi all

I use swiftmailer for sending mail and my code is

$mailSubject = "Membership Form Verification - Approved";

                $mailBody = $this->renderPartial('//mails/approvetemplate', ['compname'=>$compname, 'status'=>'Approved']);




                            ->setFrom([$fromEmail => $fromName])




But my users are compaining that the mail doesn’t come to inbox what should I do ?

Hi Anilcoder,

That is not enough information to help.

It could have a ton of reasons when your emails are detected as spam.

Also there are a lot of resources on the web to figure out why your emails are detected as spam.

For example:

(… Ignore the self-advertisement of sendgrid, just read the blog post. ;))

Just google for: "yii2 why are my emails spam"

You find or example:


Also we would need more details about your email configuration.

Are you using own hosted/rent Mailserver?

Or are you using - for example - Gmail-Servers to relay/forward your emails to the users? From my experience a common mistake is using for example google mailservers and faking the "from" address…


'mail' => [

            'class' => 'yii\swiftmailer\Mailer',

            //'useFileTransport' => true, //for the testing purpose, you need to enable this

            'transport' => [

                     'class' => 'Swift_SmtpTransport',

                    'host' => 'smtp.office123.com',

                    'username' => 'info@mydomain.com',

                    'password' => 'fghgfh',

                    'port' => '587',

                    'encryption' => 'tls',



Here is my swiftmailer config

Hello buddy You can simply use the php mail function…It will work absolutely perfect…

Building multipart messages with attachments, etc., safely escaping all user inputs and creating proper headers manually isn’t too much fun, requires quite a bit of knowledge about standards and extremely error-prone.

Also, depending on your OS and PHP configuration, mail() might happily return TRUE- even if your SMTP server is down (or simply not yet installed). And when it returns FALSE - good luck with debugging it. I prefer to have a bit more detailed and more reliable feedback about my emails.

Well then, please suggest us any standard solution…cause I am in Yii2, having not too much knowledge about it…

Thank You