M
M
Maxim Timofeev2015-06-03 18:33:47
Yii
Maxim Timofeev, 2015-06-03 18:33:47

How to connect swiftmailer (Yii2) and Yandex mail for domain?

In config:

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.yandex.ru',
                'username' => '[email protected]',
                'password' => 'тут пароль',
                'port' => '465',
                'encryption' => 'SSL',
            ],
        ],

In the model:
public function sendEmail()
    {

        $mailbody = '<h3>Отзыв с сайта</h3>
                            <p><b>Имя:</b> '.$this->name.'</p>
                            <p><b>e-mail:</b> '.$this->email.'</p>
                            <p><b>Тема:</b> '.$this->subject.'</p>
                            <p><b>Текст:</b></p>
                            <p>'.$this->body.'</p>
                            <a href="mailTo:'.$this->email.'">Ответить</a>
                            ';
        return Yii::$app->mailer->compose()
        ->setFrom('[email protected]')
        ->setTo('[email protected]')
        ->setSubject($this->subject)
        ->setTextBody($mailbody)
        ->send();
    }

At the same time I get:
Connection could not be established with host smtp.yandex.ru [Unable to find the socket transport "SSL" - did you forget to enable it when you configured PHP? #-1217465860] I
contacted the hosters, they say that I need to dig in the script because everything works for them (SSL).
Already the brain bursts with this supposedly very convenient swiftmailer. Help with advice or advise an analogue to send yourself an email from the feedback form.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
E
Eugene, 2016-07-20
@webinar

'host' => 'ssl://smtp.yandex.com',
and the rest is all right, just 'encryption' => 'SSL',
need to remove

R
Ramir1, 2016-08-16
@Ramir1

Carried. I'll add it so I don't forget.
I tried to send via mailbox registered on pdd.yandex.ru and got error
It turned out that it was necessary to enter the mailbox through the web interface and fill in the fields.

V
Vitaly Khomenko, 2015-06-03
@iiifx

SSL > TLS

N
Nazar Mokrinsky, 2015-06-03
@nazarpc

AND 465 > 587

C
craigy_waigy, 2019-09-26
@craigy_waigy

It works for me like this:

'mailer' => [
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.yandex.ru',
                'username' => 'мыло для домена',
                'password' => 'пароль',
                'port' => '25',
                'encryption' => 'tls',
            ],
        ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question