Swift_Message::addPart PHP Метод

addPart() публичный Метод

Add a MimePart to this Message.
public addPart ( string | Swift_OutputByteStream $body, string $contentType = null, string $charset = null ) : Swift_Mime_SimpleMessage
$body string | Swift_OutputByteStream
$contentType string
$charset string
Результат Swift_Mime_SimpleMessage
    public function addPart($body, $contentType = null, $charset = null)
    {
        return $this->attach(new Swift_MimePart($body, $contentType, $charset));
    }

Usage Example

Пример #1
2
 public function sendMessage()
 {
     $transport = \Swift_SmtpTransport::newInstance($this->mta->address, $this->mta->port);
     $swift = \Swift_Mailer::newInstance($transport);
     $message = new \Swift_Message();
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-GreenArrow-MailClass', 'SIGMA_NEWEMKTG_DEVEL');
     $message->setSubject($this->data->subject);
     $message->setFrom(array($this->data->fromEmail => $this->data->fromName));
     $message->setBody($this->html, 'text/html');
     $message->addPart($this->plainText, 'text/plain');
     $this->logger->log("Crea contenido del correo para enviar");
     foreach ($this->data->target as $to) {
         $message->setTo($to);
         $this->logger->log("Preparandose para enviar mensaje a: {$to}");
         $recipients = $swift->send($message, $failures);
         if ($recipients) {
             \Phalcon\DI::getDefault()->get('logger')->log('Recover Password Message successfully sent!');
         } else {
             throw new Exception('Error while sending message: ' . $failures);
         }
     }
 }
All Usage Examples Of Swift_Message::addPart