Reputation:
I have a problem when sending email messages via the form from the contact tab. I had configure in web.php
like
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '[email protected]',
'password' => 'PASSWORD',
'port' => '587',
'encryption' => 'tls'
],
'useFileTransport' => false,
]
but when I send a completed form, I do not receive any messages on my inbox. I do not get any error either. When I check in Yii Debugger, log messages show that:
13:14:10.377 info yii\mail\BaseMailer::send Sending email "dasdasdasd" to "[email protected]"
13:14:10.377 info yii\swiftmailer\Mailer::sendMessage Sending email "dasdasdasd" to "[email protected]"
Why it shows that it sent a message to a different address than what I gave? Where is problem?
SiteController:
public function actionContact() {
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
Upvotes: 0
Views: 3209
Reputation: 1105
Allow less secure apps to access your Gmail account
To disable this security feature:
This setting may not be available for:
Yii::$app->mailer->compose()
->setFrom('<fromUsername>@<yourDomain>')
->setTo('<user@Email>')
->setSubject('Уведемление с сайта <yourDomain>') // тема письма
->setTextBody('Текстовая версия письма (без HTML)')
->setHtmlBody('<p>HTML версия письма</p>')
->send();
If you are using localhost, you should "Comment" the swiftmailer settings.For example, for XAMPP, you need to do related settings and you do not need swiftmailer. Configure in (php.ini file - sendmail.ini ).
And for other programs, the necessary settings ...
Upvotes: 2