M
M
Maxim2018-03-21 00:09:33
Yii
Maxim, 2018-03-21 00:09:33

Yii2 outputting errors when sending messages?

Hello! Tell me how you can display "feedback" when sending a message. For example, the message was sent, the email address does not exist, or other errors from the server?
Faced with such a problem. When sent via:

Yii::$app->mailer->compose([
                'text' => 'views/appointment/' . $_view . '-text',
            ], $jugle_data)->setTo([$_email => $Appointment->profile->name])
                ->setSubject($judge_subject)
                ->send();
, caught an E-mail that does not exist. The script gives the following error
Expected response code 250 but got code "550", with message "550 Message was not accepted -- invalid mailbox. Local mailbox [email protected] is unavailable: user not found
"

5ab1781156fe5557244948.png
Messages are sent via cron. The script runs once a day. How can I display such errors to the user?
Also, if such errors are present, then do not mark the status of the message as "sent" in the database. And in another field, write down the reason.
Maybe through try?
//Пробуем (try) что-либо сделать.
            try{
               
            }
            //Перехватываем (catch) исключение, если что-то идет не так.
            catch (Exception $ex) {
                //Выводим сообщение об исключении.
                echo $ex->getMessage();
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2018-03-21
@myks92

catch(\Swift_TransportException $error)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question