A message represents the settings and content of an email, such as the sender, recipient, subject, body, etc. Messages are sent by a [[\yii\mail\MailerInterface|mailer]], like the following, ~~~ Yii::$app->mailer->compose() ->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) ->setTextBody('Plain text content') ->setHtmlBody('HTML content') ->send(); ~~~
See also: MailerInterface
Since: 2.0
Author: Paul Klimov (klimov.paul@gmail.com)
Exemplo n.º 1
0
 /**
  * Will write log to database
  * @param boolean $result
  * @param MessageInterface $message
  */
 public function createLog($result, $message)
 {
     $mail = new Mail();
     $mail->estado = $result ? Mail::IS_SENT : Mail::IS_NOT_SENT;
     $mail->created_at = time();
     $mail->controller = \Yii::$app->controller->id;
     $mail->action = \Yii::$app->controller->action->id;
     $temp = [];
     //store emails as string
     foreach ($message->getTo() as $email => $name) {
         $temp[] = $email;
     }
     $mail->emails = implode(', ', $temp);
     $mail->body = $message->toString();
     $mail->save();
 }
Exemplo n.º 2
0
 /**
  * Will write log to database
  * @param boolean $result
  * @param MessageInterface $message
  */
 public function crearLog($result, $message)
 {
     $controlador = !empty(Yii::$app->controller->id) ? Yii::$app->controller->id : 'controller_tst';
     $accion = !empty(Yii::$app->controller->action->id) ? Yii::$app->controller->action->id : 'action_tst';
     $mail = new CorreosLog();
     $mail->estado = $result ? CorreosLog::ENVIADO : CorreosLog::NO_ENVIADO;
     $mail->fecha = time();
     $mail->controlador = $controlador;
     $mail->accion = $accion;
     $temp = [];
     //store emails as string
     foreach ($message->getTo() as $email => $name) {
         $temp[] = $email;
     }
     $mail->correos = implode(', ', $temp);
     $mail->mensaje = $message->toString();
     $mail->save();
 }