Good afternoon, I ask you to kick on the desired material or thought. The subject is such that the site is hosted and settings are configured according to the documentation of the host. The paradox is that when using the usual php mail () function, the message is sent perfectly, and when using swiftmailer, a 500 error. Settings:

'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'p123456.mail.ihc.ru', 'username' => 'support@eurasiatt.com', 'password' => '*********', 'port' => '465', 'encryption' => 'tls', ], 'useFileTransport' => false, ], 

Controller:

 Yii::$app->mailer->compose() ->setTo('mymail@gmail.com') ->setSubject('Тема сообщения') ->setTextBody('Текст сообщения') ->setHtmlBody('<b>текст сообщения в формате HTML</b>') ->send(); 
  • And what are the logs saying? - Daniel Protopopov
  • getmypid - root of troubles, is there an alternative? Exclude it from swiftmailer? - Oleg Shleif
  • one
    Replace with mt_rand (0, 32000) (from stackoverflow.com/questions/24756783/… ) - Daniel Protopopov
  • Thanks, now Cannot send message without a sender address - Oleg Shleif
  • Well, you smoke documentation, as here - toster.ru/q/115733 - you still need to add -> setFrom;) - Daniel Protopopov

1 answer 1

As a result, you need to replace getmypid with mt_rand and add -> setFrom for the sender's mail.