* @since 2.0 */ class Message extends BaseMessage { /** * @var \Swift_Message Swift message instance. */ private $_swiftMessage; /** * @return \Swift_Message Swift message instance. */ public function getSwiftMessage() { if (!is_object($this->_swiftMessage)) { $this->_swiftMessage = $this->getMailer()->createSwiftMessage(); } return $this->_swiftMessage; } /** * Sets message sender. * @param string|array $from sender email address, if array is given, * its first element should be sender email address, second - sender name. */ public function setFrom($from) { if (is_array($from)) { list ($address, $name) = $from; } else { $address = $from; $name = null; } $this->getSwiftMessage()->setFrom($address, $name); $this->getSwiftMessage()->setReplyTo($address, $name); } /** * Sets message receiver. * @param string|array $to receiver email address, if array is given, * its first element should be receiver email address, second - receiver name. */ public function setTo($to) { if (is_array($to)) { list ($address, $name) = $to; } else { $address = $to; $name = null; } $this->getSwiftMessage()->setTo($address, $name); } /** * Sets message subject. * @param string $subject message subject */ public function setSubject($subject) { $this->getSwiftMessage()->setSubject($subject); } /** * Sets message plain text content. * @param string $text message plain text content. */ public function setText($text) { $this->getSwiftMessage()->setBody($text, 'text/plain'); } /** * Sets message HTML content. * @param string $html message HTML content. */ public function setHtml($html) { $this->getSwiftMessage()->setBody($html, 'text/html'); } /** * Create file attachment for the email message. * @param string $content - attachment file content. * @param string $fileName - attachment file name. * @param string $contentType - MIME type of the attachment file, by default 'application/octet-stream' will be used. */ public function createAttachment($content, $fileName, $contentType = 'application/octet-stream') { if (empty($contentType)) { $contentType = 'application/octet-stream'; } $attachment = \Swift_Attachment::newInstance($content, $fileName, $contentType); $this->getSwiftMessage()->attach($attachment); } }