Example #1
0
 public function send()
 {
     //Yii::import('application.extensions.smtpmail.PHPMailer');
     $mailer = new \yii\swiftmailer\Mailer(["transport" => ['class' => 'Swift_SmtpTransport', 'host' => \app\helpers\Linet3Helper::getSetting('company.mail.server'), 'username' => \app\helpers\Linet3Helper::getSetting('company.mail.user'), 'password' => \app\helpers\Linet3Helper::getSetting('company.mail.password'), 'port' => \app\helpers\Linet3Helper::getSetting('company.mail.port'), 'encryption' => \app\helpers\Linet3Helper::getSetting('company.mail.ssl') ? 'tls' : '']]);
     $mail = $mailer->compose('layouts/html', ['content' => $this->body]);
     //$mail->SetFrom($this->from);
     //echo $this->files;
     if ($this->files != '') {
         $file = Files::findOne($this->files);
         if ($file != null) {
             //echo $file->getFullPath().";;".$file->name;
             $mail->attach($file->getFullFilePath(), ["fileName" => $file->name]);
         }
     }
     $mail->setFrom(\app\helpers\Linet3Helper::getSetting('company.mail.address'))->setTo($this->to)->setSubject($this->subject);
     if ($this->cc != '') {
         $mail->setCc($this->cc);
     }
     if ($this->bcc != '') {
         $mail->setBcc($this->bcc);
     }
     //$mail->AddCC($this->cc); //.$this->cc
     //$mail->AddBcc($this->bcc);
     //$mail->
     //$mail->setHtmlBody($this->body);
     //$mail;
     if (!$mail->send()) {
         //echo "Mailer Error: " . $mail->ErrorInfo;
         throw new Exception(Yii::t('app', "Mailer Error: ") . $mail->ErrorInfo . $mail->Username);
     } else {
         $this->sent++;
         $this->save();
         if (!\app\helpers\Linet3Helper::isConsole()) {
             \Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Message sent!'));
         }
         //echo "Message sent!";
     }
     //*/
     //Yii::$app->end();
 }