I was stuck on this a little time longer than usual… but i hope this information can be helpful for someone out there… when i was trying to send mail i got the handshake error and others using hostgator including Swift_TransportException and ][error][Swift_TransportException] exception ‘Swift_TransportException’ with message 'Expected response code 250 but got code “334”,
the thing is if you’re trying to send mail using hostgator you should change (DEV enviroment) app/common/config/main-local.php from this:
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=<<your DB name>>',
'username' => <<your DB username>>,
'password' => <<your DB password>>,
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
],
'as beforeRequest' => [ // this is a rule that force everyone to redirect to login
'class' => 'yii\filters\AccessControl',
'rules' => [
[
'actions' => ['login'],
'allow' => true,
],
[
'allow' => true,
'roles' => ['@'],
],
],
],
'language'=>'es', // this is the default language like the locale
];
?>
to this :
<?php
return ...<<your other components>>
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => <<your host>>,
'username' => <<your username with your subdomain or domain (@),
'password' => <<your password>>,
'port' => '465',
'encryption' => 'ssl',
],
],
],
?>
and in your controller only make a request via GET by inserting this function:
public function actionTestingyii2mailing() {
Yii::$app->mailer->compose()
->setFrom('yourusername@youemail.com')
->setTo('emailtobesent@senderemail.com')
->setSubject('here are your subject with an empty body')
->send();
print_r("if you can see this print and your environment is in dev mode then your email has been sent");
}
try to access to this (lowercase) method via r=myclass/testingyii2mailing
hope someone can be helpful i stayed in this for almost 4 hours intensively…
please note your domain should be allowed to send mail… in my case is hostgator and the port is 465 and not 581 that comes
i resolved this when i was writing this post so…
Enjoy!!!