yupe\components\Mail::send PHP Method

send() public method

Функция отправки сообщения:
public send ( string $from, string | array $to, string $theme, string $body, boolean $isText = false, array $replyTo = [] ) : boolean
$from string - адрес отправителя
$to string | array - адрес(-а) получателя
$theme string - тема письма
$body string - тело письма
$isText boolean - является ли тело письма текстом
$replyTo array добавляет заголовок Reply-To, формат [email => имя]
return boolean отправилось ли письмо
    public function send($from, $to, $theme, $body, $isText = false, $replyTo = [])
    {
        $this->_mailer->clearAllRecipients();
        $this->setFrom($from);
        if (is_array($to)) {
            foreach ($to as $email) {
                $this->addAddress($email);
            }
        } else {
            $this->addAddress($to);
        }
        $this->setSubject($theme);
        if ($isText) {
            $this->_mailer->Body = $body;
            $this->_mailer->isHTML(false);
        } else {
            $this->_mailer->msgHTML($body, \Yii::app()->basePath);
        }
        if (!empty($replyTo)) {
            $this->_mailer->clearReplyTos();
            foreach ($replyTo as $email => $name) {
                $this->_mailer->addReplyTo($email, $name);
            }
        }
        try {
            return $this->_mailer->send();
        } catch (\Exception $e) {
            \Yii::log($e->__toString(), \CLogger::LEVEL_ERROR, 'mail');
            return false;
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param IFeedbackForm $form
  * @param FeedBack|null $feedBack
  * @return bool
  */
 public function sendConfirmation(IFeedbackForm $form, FeedBack $feedBack = null)
 {
     $emailBody = Yii::app()->controller->renderPartial('feedbackConfirmationEmail', ['model' => $feedBack], true);
     $result = $this->mail->send($this->module->notifyEmailFrom, $form->getEmail(), Yii::t('FeedbackModule.feedback', 'Your proposition on site "{site}" was received', ['{site}' => Yii::app()->name]), $emailBody);
     if ($result) {
         Yii::log(Yii::t('FeedbackModule.feedback', 'Feedback: Notification for user was sent to email successfully'), CLogger::LEVEL_INFO, FeedbackModule::$logCategory);
     } else {
         Yii::log(Yii::t('FeedbackModule.feedback', 'Feedback: can\'t send message'), CLogger::LEVEL_INFO, FeedbackModule::$logCategory);
     }
     return $result;
 }
All Usage Examples Of yupe\components\Mail::send