/** * Устанавливаем дополнительные заголовки писем * * @param Message $letter * @param array $aData * */ public static function setAntiSpamHeaders(&$letter, $aData = []) { $oMsg = $letter->getSwiftMessage(); $headers = $oMsg->getHeaders(); $headers->addTextHeader('Precedence', 'bulk'); $headers->addTextHeader('Auto-Submitted', 'auto-generated'); $email = ''; $site = $_SERVER['HTTP_HOST']; if (isset($aData['email'])) { $email = $aData['email']; } else { if (isset(Yii::$app->params['contactEmail'])) { $email = Yii::$app->params['contactEmail']; } } if (isset($aData['site'])) { $site = $aData['site']; } if ($email !== '') { $headers->addTextHeader('Error-to', '<' . $email . '>'); $headers->addTextHeader('List-Owner', '<' . $email . '>'); $headers->addTextHeader('List-Unsubscribe', '<mailto:' . $email . '>,<http://' . $site . '/>'); } }
/** * @param \common\commands\SendEmailCommand $command * @return bool */ public function handle($command) { if (!$command->body) { $message = \Yii::$app->mailer->compose($command->view, $command->params); } else { $message = new Message(); if ($command->isHtml()) { $message->setHtmlBody($command->body); } else { $message->setTextBody($command->body); } } $message->setFrom($command->from); $message->setTo($command->to ?: \Yii::$app->params['robotEmail']); $message->setSubject($command->subject); return $message->send(); }
/** * @depends testGetSwiftMessage */ public function testSetGet() { $message = new Message(); $charset = 'utf-16'; $message->setCharset($charset); $this->assertEquals($charset, $message->getCharset(), 'Unable to set charset!'); $subject = 'Test Subject'; $message->setSubject($subject); $this->assertEquals($subject, $message->getSubject(), 'Unable to set subject!'); $from = '*****@*****.**'; $message->setFrom($from); $this->assertContains($from, array_keys($message->getFrom()), 'Unable to set from!'); $replyTo = '*****@*****.**'; $message->setReplyTo($replyTo); $this->assertContains($replyTo, array_keys($message->getReplyTo()), 'Unable to set replyTo!'); $to = '*****@*****.**'; $message->setTo($to); $this->assertContains($to, array_keys($message->getTo()), 'Unable to set to!'); $cc = '*****@*****.**'; $message->setCc($cc); $this->assertContains($cc, array_keys($message->getCc()), 'Unable to set cc!'); $bcc = '*****@*****.**'; $message->setBcc($bcc); $this->assertContains($bcc, array_keys($message->getBcc()), 'Unable to set bcc!'); }
/** @inheritdoc */ public function setTextBody($text) { $this->_text = $text; return parent::setTextBody($text); }
/** * @inheritdoc */ public function attach($fileName, array $options = []) { array_push($this->attachments, $fileName); parent::attach($fileName, $options); return $this; }