@param string $subject
@param string $body
@param string $contentType
@param string $charset

@return Swift_Message
519083
public function createMessage($subject = null, $body = null, $contentType = null, $charset = null)
    {
        $message = Swift_Message::newInstance($subject, $body, $contentType, $charset);

        if(null !== $this->fromEmail) {
            
            if(null === $this->fromName) {
                $message->setFrom($this->fromEmail);
            } else {
                $message->setFrom($this->fromEmail, $this->fromName);
            }
            
        }

        return $message;
    }
406410
public function sendHtml ($subject, $contentHTML, $to, $cc=array(), $bcc=array())
    {
        $firstErrorMsg = '';
        $lastErrorMsg  = '';

        // Try gateways in order
        foreach ($this->gateways as $gw) {
            try {
                $gw->sendHtml($subject, $contentHTML, $to, $cc, $bcc);

                // If previous function did not throw an exception, mail deportation was successfull
                return;

            } catch (\Exception $e) {
                // Sending failed, try, next gw, store error message
                if ('' === $firstErrorMsg) {
                    $firstErrorMsg = $e->getMessage();
                }
                $lastErrorMsg = $e->getMessage();
            }
        }

        // If we reach this point, we know all GWs failed
        throw new Exception("Sending email failed through all gateways (". count($this->gateways) ." configured).\n\nFirst error message: $firstErrorMsg\nLast error message: $lastErrorMsg");
    }
999139
public function setSubject($subject)
    {
        if (!is_string($subject)) {
            throw new TypeException('$subject must be of type string.');
        }
        if (!($subject instanceof Subject)) {
            $this->subject = new Subject($subject);
        } else {
            $this->subject = $subject;
        }
    }
473476
public function setTextMessage(array $to,
                                   string $subject,
                                   string $body,
                                   array $attachment = null,
                                   array $cc = null,
                                   array $bcc = EMAIL_BCC): void
    {
        $this->email->setFrom($this->from);
        foreach ($to as $value) {
            $this->email->addTo($value);
        }
        if ($cc != null) {
            foreach ($cc as $value) {
                $this->email->addCc($value);
            }
        }
        if ($bcc != null) {
            foreach ($bcc as $value) {
                $this->email->addBcc($value);
            }
        }
        if ($attachment != null) {
            foreach ($attachment as $file) {
                $this->email->addAttachment($file);
            }
        }
        $this->email->setSubject($subject);
        $this->email->setBody($body);
    }
794172
public function contentType($contentType, $charset = 'utf-8') {

        $this->contentType = $contentType;
        $this->charset = $charset;
        return $this;
    }
1344110
public static function send(string $to, string $subject, string $view, array $viewVars = [], $builder = null, $from = 'default')
    {
        $message = static::createMessage($to, $subject, $from);
        if (is_callable($builder)) {
            $builder($message);
        }
        $message->setBody(static::view($view, $viewVars));

        self::getMailer()->send($message);
    }
1067117
protected function getDefaultMessage($from, $encoding, $to, $subject, $body) {
        if(is_string($from)) {
            $from = array('email' => $from, 'name' => $from);
        }

        $message = new MailMessage();
        $message->setFrom($from['email'], $from['name'])
            ->setEncoding($encoding)
            ->setSubject($subject)
            ->setBody($body)
            ->setTo($to);

        return $message;
    }
1234871
public function withContentType($contentType, $charset = null)
    {
        if (is_null($charset)) {
            return $this->withHeader('Content-Type', $contentType);
        }

        return $this->withHeader('Content-Type', $contentType . '; charset=' . $charset);
    }
913631
public function setSubject($subject) {
    if (!is_string($subject)) {
      $error = sprintf("Subject given is not a string (Actual type: %s).",
               gettype($subject));
      throw new \InvalidArgumentException($error);
    }
    $this->message->setSubject($subject);
  }
926548
public function send($mailAddress, $username, $subject, $body)
    {
        $subject = $this->translator->trans($subject);
        $body = $this->translator->trans(
            $body,
            ['%username%' => $username]
        );

        $message = $this->messageFactory->create();
        $message
            ->setSubject($subject)
            ->setFrom($this->mailerAddress)
            ->setTo($mailAddress)
            ->setBody($body);

        return $this->mailer->send($message);
    }
1178498
public function setBody($body, $contentType = null, $charset = null)
    {
        if (isset($charset)) {
            $this->setCharset($charset);
        }
        $body = $this->convertString($body);

        parent::setBody($body, $contentType);

        return $this;
    }
700525
public function addContent(string $content, string $contentType, ?string $charset = null): Message
    {
        $charset = $charset ?: $this->getCharset();

        $this->content[] = [
            'content'      => $content,
            'content_type' => $contentType,
            'charset'      => $charset
        ];

        return $this;
    }
814603
private function sendEmail(UserInterface $user, \Swift_Mailer $mailer, $subject, $body, $templateId)
    {
        if (\is_array($body)) {
            $body['email'] = $user->getEmail();
            $body['fullname'] = $user->getProfile()->getFullName();
        } else {
            $body = [
                'email' => $user->getEmail(),
                'fullname' => $user->getProfile()->getFullName(),
                'content' => $body,
            ];
        }

        // Create Message
        $message = (new PdSwiftMessage())
            ->setTemplateId($templateId)
            ->setFrom($this->getParameter('pd_user.mail_sender_address'), $this->getParameter('pd_user.mail_sender_name'))
            ->setTo($user->getEmail())
            ->setSubject($subject)
            ->setBody(serialize($body), 'text/html');

        return (bool)$mailer->send($message);
    }
396401
public function send($subject, $html, $from, $receivers, $attaches = null)
    {
        // Create the Mailer using your created Transport
        $mailer = new Swift_Mailer($this->mail);
        // Create a message
        $message = (new Swift_Message($subject))
            ->setFrom([$this->options['username'] => $from])
            ->setTo($receivers);
        $message->charsetChanged('utf-8');
        $message->setBody($html, Arrays::get($this->options, 'contentType', 'text/html'));
        //attach
        if($attaches && is_array($attaches)){
            foreach ($attaches as $attachItem) {
                $message->attach(Swift_Attachment::fromPath(
                    Arrays::get($attachItem, 'filename'), Arrays::get($attachItem, 'contentType'))->setFilename(Arrays::get($attachItem, 'name')));//附件图片
            }
        }
        // Send the message
        $result = $mailer->send($message);
        // TCP port to connect to
        return $result;
    }
482742
public function message($to, $body, $type = 'chat', $subject = null, $payload = null) {
	    if(is_null($type))
	    {
	        $type = 'chat';
	    }
	    
		$to	  = htmlspecialchars($to);
		$body	= htmlspecialchars($body);
		$subject = htmlspecialchars($subject);
		
		$out = "<message from=\"{$this->fulljid}\" to=\"$to\" type='$type'>";
		if($subject) $out .= "<subject>$subject</subject>";
		$out .= "<body>$body</body>";
		if($payload) $out .= $payload;
		$out .= "</message>";
		
		$this->send($out);
	}
173576
public function setSubject($subject)
	{
		$this->getComposer()->subject = $subject;
		$this->getComposer()->subjectCharset = CHARSET;

		return $this;
	}
1372877
public static function getPlainMail($to, $from, $body, $subject) {
        $mail = new MailMessage($to, $from, $body, $subject);
        return $mail;
    }