MikelG
MikelG

Reputation: 489

Sending emails from Yii2 and wampserver 2.5

I am using Yii2 in conjunction with wampserver 2.5 for my project. What I am trying to do is rather basic: I just need to be able to send emails from my local machine.

I have tried various tutorials and how-to's from across the internet and none have worked so far. I am trying to use swiftmailer, which is included in Yii2 with smtp.gmail.com.

I would really appreciate if someone using this combination (Yii2 and wampserver 2.5) could help me here.

Upvotes: 0

Views: 2251

Answers (1)

Dency G B
Dency G B

Reputation: 8146

I use xampp server with yii2 and swiftmailer extension.I configured my swiftmailer to use my gmail as smtp to send mails.Following is my code.

In the components's section of your common/main-local.php

'mail' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@backend/mail',
        'useFileTransport' => false,//to send mails to real email addresses else will get stored in your mail/runtime folder
        //comment the following array to send mail using php's mail function
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => '[email protected]',
            'password' => 'password',
            'port' => '587',
            'encryption' => 'tls',
                        ],
    ],
    ],

In your Controller

    \Yii::$app->mail->compose('your_view', ['params' => $params])
    ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail'])
    ->setTo('[email protected]')
    ->setSubject('This is a test mail ' )
    ->send();

This should work! Hope this will help you!

Upvotes: 2

Related Questions