Reputation: 51
I'm using yii2 and I'm totally new to this can someone help me with sending emails in this framework I'm using swiftmailer and have set the configurations as:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => false,
]
Upvotes: 1
Views: 2219
Reputation: 97
Please check your port this was my problem when i worked with mailer in yii2
Upvotes: 0
Reputation: 31
add below code in your common->config->main-local.php
file under components section:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '[email protected]',
'password' => 'password',
'port' => '465',
'encryption' => 'ssl',
],
],
Upvotes: 0
Reputation: 261
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport'=>false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '[email protected]',
'password' => 'password',
'port' => '465',
'encryption' => 'ssl',
],
],
Add these lines to config/main.php. Make a view for your mail body and give path to that view in below function and use that code you want to send the mail
$check=Yii::$app->mailer->compose('../../frontend/views/mail', ['data'=> 'Mail data'])
->setFrom('[email protected]')
->setTo('[email protected]')
->setSubject('check sending mail')
->send();
var_dump($check);
Upvotes: 1
Reputation: 133360
You need to configure the transport correctly
In this example i suppose you use gmail, if this is not true you need change the values with your values.
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '[email protected]',
'password' => 'yourPassword',
'port' => '587',
'encryption' => 'tls',
],
],
Upvotes: 0