当前位置: 首页>>代码示例>>PHP>>正文


PHP Swift_Message::setBody方法代码示例

本文整理汇总了PHP中Swift_Message::setBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::setBody方法的具体用法?PHP Swift_Message::setBody怎么用?PHP Swift_Message::setBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Swift_Message的用法示例。


在下文中一共展示了Swift_Message::setBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fromWrappedMessage

 /**
  * @inheritDoc
  */
 public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null)
 {
     if (!$wrappedMessage instanceof MailWrappedMessage) {
         throw new MailWrapperSetupException('Not MailWrappedMessage');
     }
     $message = new \Swift_Message();
     foreach ($wrappedMessage->getToRecipients() as $address) {
         $message->addTo($address);
     }
     foreach ($wrappedMessage->getCcRecipients() as $address) {
         $message->addCc($address);
     }
     foreach ($wrappedMessage->getBccRecipients() as $address) {
         $message->addBcc($address);
     }
     $message->setReplyTo($wrappedMessage->getReplyTo());
     $message->setFrom($wrappedMessage->getFrom());
     $message->setSubject($wrappedMessage->getSubject());
     if ($wrappedMessage->getContentText()) {
         $message->setBody($wrappedMessage->getContentText());
     }
     if ($wrappedMessage->getContentHtml()) {
         $message->setBody($wrappedMessage->getContentHtml(), 'text/html');
     }
     return $message;
 }
开发者ID:BespokeSupport,项目名称:MailWrapper,代码行数:29,代码来源:MessageTransformerSwift.php

示例2: send

 /**
  * @param string $name
  * @param array  $context
  * @param callable|null $callback a callback to modify the mail before it is sent.
  */
 public function send($name, array $context = [], callable $callback = null)
 {
     $template = $this->twig->loadTemplate($name);
     $blocks = [];
     foreach (['from', 'from_name', 'to', 'to_name', 'subject', 'body_txt', 'body_html'] as $blockName) {
         $rendered = $this->renderBlock($template, $blockName, $context);
         if ($rendered) {
             $blocks[$blockName] = $rendered;
         }
     }
     $blocks = array_merge($context, $blocks);
     $mail = new \Swift_Message();
     $mail->setSubject($blocks['subject']);
     $mail->setFrom(isset($blocks['from_name']) ? [$blocks['from'] => $blocks['from_name']] : $blocks['from']);
     if (isset($blocks['to'])) {
         $mail->setTo(isset($blocks['to_name']) ? [$blocks['to'] => $blocks['to_name']] : $blocks['to']);
     }
     if (isset($blocks['body_txt']) && isset($blocks['body_html'])) {
         $mail->setBody($blocks['body_txt']);
         $mail->addPart($blocks['body_html'], 'text/html');
     } elseif (isset($blocks['body_txt'])) {
         $mail->setBody($blocks['body_txt']);
     } elseif (isset($blocks['body_html'])) {
         $mail->setBody($blocks['body_html'], 'text/html');
     }
     if ($callback) {
         $callback($mail);
     }
     $this->mailer->send($mail);
 }
开发者ID:jvasseur,项目名称:mail-sender,代码行数:35,代码来源:MailSender.php

示例3: _mapToSwift

 protected function _mapToSwift(SendGrid\Email $mail)
 {
     $message = new \Swift_Message($mail->getSubject());
     /*
      * Since we're sending transactional email, we want the message to go to one person at a time, rather
      * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
      * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be 
      * ignored anyway.
      */
     $message->setTo($mail->to);
     $message->setFrom($mail->getFrom(true));
     $message->setCc($mail->getCcs());
     $message->setBcc($mail->getBccs());
     if ($mail->getHtml()) {
         $message->setBody($mail->getHtml(), 'text/html');
         if ($mail->getText()) {
             $message->addPart($mail->getText(), 'text/plain');
         }
     } else {
         $message->setBody($mail->getText(), 'text/plain');
     }
     if ($replyto = $mail->getReplyTo()) {
         $message->setReplyTo($replyto);
     }
     $attachments = $mail->getAttachments();
     //add any attachments that were added
     if ($attachments) {
         foreach ($attachments as $attachment) {
             $message->attach(\Swift_Attachment::fromPath($attachment['file']));
         }
     }
     $message_headers = $message->getHeaders();
     $message_headers->addTextHeader("x-smtpapi", $mail->smtpapi->jsonString());
     return $message;
 }
开发者ID:alpha1,项目名称:sendgrid-wordpress,代码行数:35,代码来源:class-sendgrid-smtp.php

示例4: send

 /**
  * @param string               $subject
  * @param string               $body
  * @param array|string         $to
  * @param array|string         $from
  * @param array|Attachment|null    $attachments
  * @return int
  */
 public function send($subject, $body, $to, $from, $attachments = null)
 {
     $this->message->setSubject($subject);
     $this->message->setFrom($from);
     $this->message->setTo($to);
     $this->message->setBody($body, self::BODY_TYPE);
     $this->processAttachments($attachments);
     return $this->mailer->send($this->message);
 }
开发者ID:stackinstance,项目名称:mailer-bundle,代码行数:17,代码来源:Mailer.php

示例5: _mapToSwift

 protected function _mapToSwift(Mail $mail)
 {
     $message = new \Swift_Message($mail->getSubject());
     /*
      * Since we're sending transactional email, we want the message to go to one person at a time, rather
      * than a bulk send on one message. In order to do this, we'll have to send the list of recipients through the headers
      * but Swift still requires a 'to' address. So we'll falsify it with the from address, as it will be 
      * ignored anyway.
      */
     $message->setTo($mail->getFrom());
     $message->setFrom($mail->getFrom(true));
     $message->setCc($mail->getCcs());
     $message->setBcc($mail->getBccs());
     if ($mail->getHtml()) {
         $message->setBody($mail->getHtml(), 'text/html');
         if ($mail->getText()) {
             $message->addPart($mail->getText(), 'text/plain');
         }
     } else {
         $message->setBody($mail->getText(), 'text/plain');
     }
     if ($replyto = $mail->getReplyTo()) {
         $message->setReplyTo($replyto);
     }
     // determine whether or not we can use SMTP recipients (non header based)
     if ($mail->useHeaders()) {
         //send header based email
         $message->setTo($mail->getFrom());
         //here we'll add the recipients list to the headers
         $headers = $mail->getHeaders();
         $headers['to'] = $mail->getTos();
         $mail->setHeaders($headers);
     } else {
         $recipients = array();
         foreach ($mail->getTos() as $recipient) {
             if (preg_match("/(.*)<(.*)>/", $recipient, $results)) {
                 $recipients[trim($results[2])] = trim($results[1]);
             } else {
                 $recipients[] = $recipient;
             }
         }
         $message->setTo($recipients);
     }
     $attachments = $mail->getAttachments();
     //add any attachments that were added
     if ($attachments) {
         foreach ($attachments as $attachment) {
             $message->attach(\Swift_Attachment::fromPath($attachment['file']));
         }
     }
     //add all the headers
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-SMTPAPI', $mail->getHeadersJson());
     return $message;
 }
开发者ID:vzoom96,项目名称:Hackathon-Projects,代码行数:55,代码来源:Smtp.php

示例6: addBodies

 /**
  * Add html and plain text bodies or only plain text if html is empty.
  *
  * @param \Swift_Message        $message      The swiftmailer message
  * @param MailRenderedInterface $mailRendered The rendered mail
  */
 protected function addBodies(\Swift_Message $message, MailRenderedInterface $mailRendered)
 {
     $textPlain = $mailRendered->getBody();
     $html = $mailRendered->getHtmlBody();
     if (null === $html) {
         $message->setBody($textPlain, 'text/plain');
         return;
     }
     $message->setBody($html, 'text/html');
     if (null !== $textPlain) {
         $message->addPart($textPlain, 'text/plain');
     }
 }
开发者ID:sonatra,项目名称:SonatraMailerBundle,代码行数:19,代码来源:SwiftMailerTransport.php

示例7: sendMailConSendGrid

function sendMailConSendGrid($text, $html, $subject, $from, $to)
{
    include_once "lib/php/swift/swift_required.php";
    $username = 'unovamx';
    $password = 'LanzamientoUnova2012';
    // Setup Swift mailer parameters
    $transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
    $transport->setUsername($username);
    $transport->setPassword($password);
    $swift = Swift_Mailer::newInstance($transport);
    // Create a message (subject)
    $message = new Swift_Message($subject);
    // attach the body of the email
    $message->setFrom($from);
    $message->setBody($html, 'text/html');
    $message->setTo($to);
    $message->addPart($text, 'text/plain');
    // send message
    $recipients = $swift->send($message, $failures);
    if ($recipients <= 0) {
        echo "Something went wrong - ";
        print_r($failures);
        $recipients = 0;
    }
    return $recipients;
}
开发者ID:netor27,项目名称:Unova,代码行数:26,代码来源:EmailModelo.php

示例8: _swiftMail

 protected function _swiftMail($to, $from, $subject, $message, $attachments = [], $html = true)
 {
     $mailer = $this->__getSwiftMailer($from);
     if (is_array($to) && isset($to['email'])) {
         if (isset($to['name'])) {
             $to = [$to['email'] => $to['name']];
         } else {
             $to = $to['email'];
         }
     }
     $mail = new \Swift_Message();
     $mail->setSubject($subject)->setFrom($from['email'], $from['name'])->setTo($to);
     if (isset($from['reply-to'])) {
         if (is_array($from['reply-to']) && isset($from['email'])) {
             $mail->setReplyTo($from['reply-to']['email'], $from['reply-to']['name']);
         } else {
             $mail->setReplyTo($from['reply-to']);
         }
     }
     $mail->setBody($message, $html ? 'text/html' : 'text/plain');
     foreach ($attachments as $attachment) {
         $mail->attach(\Swift_Attachment::fromPath($attachment));
     }
     return $mailer->send($mail);
 }
开发者ID:mpf-soft,项目名称:mpf,代码行数:25,代码来源:MailHelper.php

示例9: __construct

 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Recover log in'));
     if ($this->isPostBack()) {
         $this->post->email->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $user = ModelUser::getByUsername($this->input('email'));
             if (!$user->hasRow()) {
                 $this->setMessage('No user found', 'warning');
                 response()->refresh();
             }
             if (!$this->hasErrors()) {
                 $reset = new UserReset($user->id);
                 $reset->save();
                 // TODO: Move this shit to seperate html template
                 $text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
                 $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
                 $swift = \Swift_Mailer::newInstance($transport);
                 $message = new \Swift_Message(lang('Confirm password reset on NinjaImg'));
                 $message->setFrom(env('MAIL_FROM'));
                 $message->setSender(env('MAIL_FROM'));
                 $message->setReplyTo(env('MAIL_FROM'));
                 $message->setBody($text, 'text/plain');
                 $message->setTo($user->username);
                 $swift->send($message);
                 $this->setMessage('A password reset link has been sent to your e-mail', 'success');
                 // Send mail to user confirming reset...
                 // Maybe show message with text that are active even when session disappear
                 response()->refresh();
             }
         }
     }
 }
开发者ID:Monori,项目名称:imgservice,代码行数:34,代码来源:UserForgot.php

示例10: __construct

 public function __construct($key)
 {
     parent::__construct();
     $newPassword = uniqid();
     $reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword);
     if ($reset) {
         $user = ModelUser::getById($reset);
         if ($user->hasRow()) {
             // Send mail with new password
             // TODO: Move this shit to separate html template
             $user->setEmailConfirmed(true);
             $user->update();
             $text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: " . $newPassword . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
             $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
             $swift = \Swift_Mailer::newInstance($transport);
             $message = new \Swift_Message(lang('New password for NinjaImg'));
             $message->setFrom(env('MAIL_FROM'));
             $message->setSender(env('MAIL_FROM'));
             $message->setReplyTo(env('MAIL_FROM'));
             $message->setBody($text, 'text/plain');
             $message->setTo($user->username);
             $swift->send($message);
             $this->setMessage('A new password has been sent to your e-mail.', 'success');
             redirect(url('user.login'));
         }
         redirect(url('home'));
     }
 }
开发者ID:Monori,项目名称:imgservice,代码行数:28,代码来源:UserReset.php

示例11: send

 /**
  * @param $to
  * @param $subject
  * @param $body
  * @return bool
  */
 public function send($to, $subject, $body)
 {
     include_once "vendor/autoload.php";
     date_default_timezone_set("Asia/Colombo");
     $this->CI->config->load('send_grid');
     $username = $this->CI->config->item('send_grid_username');
     $password = $this->CI->config->item('send_grid_password');
     $smtp_server = $this->CI->config->item('send_grid_smtp_server');
     $smtp_server_port = $this->CI->config->item('send_grid_smtp_server_port');
     $sending_address = $this->CI->config->item('email_sender_address');
     $sending_name = $this->CI->config->item('email_sender_name');
     $from = array($sending_address => $sending_name);
     $to = array($to);
     $transport = Swift_SmtpTransport::newInstance($smtp_server, $smtp_server_port);
     $transport->setUsername($username);
     $transport->setPassword($password);
     $swift = Swift_Mailer::newInstance($transport);
     $message = new Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($body, 'text/html');
     $message->setTo($to);
     $message->addPart($body, 'text/plain');
     // send message
     if ($recipients = $swift->send($message, $failures)) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:sandeepa91,项目名称:JMS-V1,代码行数:35,代码来源:EmailSender.php

示例12: send

 /**
  * Send an email to a number of recipients
  * Returns the number of successful recipients, or FALSE on failure
  * @param mixed The recipients to send to.  One of string, array, 2-dimensional array or Swift_Address
  * @param mixed The address to send from. string or Swift_Address
  * @param string The message subject
  * @param string The message body, optional
  * @return int
  */
 public function send($recipients, $from, $subject, $body = null)
 {
     $this->addTo($recipients);
     $sender = false;
     if (is_string($from)) {
         $sender = $this->stringToAddress($from);
     } elseif ($from instanceof Swift_Address) {
         $sender = $from;
     }
     if (!$sender) {
         return false;
     }
     $this->message->setSubject($subject);
     if ($body) {
         $this->message->setBody($body);
     }
     try {
         if (!$this->exactCopy && !$this->recipients->getCc() && !$this->recipients->getBcc()) {
             $sent = $this->swift->batchSend($this->message, $this->recipients, $sender);
         } else {
             $sent = $this->swift->send($this->message, $this->recipients, $sender);
         }
         if ($this->autoFlush) {
             $this->flush();
         }
         return $sent;
     } catch (Swift_ConnectionException $e) {
         $this->setError("Sending failed:<br />" . $e->getMessage());
         return false;
     }
 }
开发者ID:darkcolonist,项目名称:kohana234-doctrine115,代码行数:40,代码来源:EasySwift.php

示例13: respond

 public function respond(array $communication, \stdClass $msg)
 {
     $result = $this->generateResponse($communication);
     if (preg_match('/^\\s*re:/', $msg->subject)) {
         $subject = $msg->subject;
     } else {
         $subject = 'Re: ' . $msg->subject;
     }
     if (isset($this->config['name'])) {
         $from = array($this->config['email_address'] => $this->config['name']);
     } else {
         $from = array($this->config['email_address']);
     }
     $to = array($msg->from_email);
     if (isset($msg->headers->{'Message-Id'})) {
         $message_id = $msg->headers->{'Message-Id'};
     } else {
         $message_id = false;
     }
     // TODO - set reply to id
     $transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
     $transport->setUsername($this->config['mandrill_username']);
     $transport->setPassword($this->config['mandrill_password']);
     $swift = \Swift_Mailer::newInstance($transport);
     $message = new \Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($result);
     $message->setTo($to);
     $result = $swift->send($message);
 }
开发者ID:sriramsv,项目名称:jarvis,代码行数:30,代码来源:MandrillBot.php

示例14: transformMessage

 /**
  * Creates a swift message from a ParsedMessage, handles defaults
  *
  * @param ParsedMessage $parsedMessage
  *
  * @return \Swift_Message
  */
 protected function transformMessage(ParsedMessage $parsedMessage)
 {
     $message = new \Swift_Message();
     if ($from = $parsedMessage->getFrom()) {
         $message->setFrom($from);
     }
     // handle to with defaults
     if ($to = $parsedMessage->getTo()) {
         $message->setTo($to);
     }
     // handle cc with defaults
     if ($cc = $parsedMessage->getCc()) {
         $message->setCc($cc);
     }
     // handle bcc with defaults
     if ($bcc = $parsedMessage->getBcc()) {
         $message->setBcc($bcc);
     }
     // handle reply to with defaults
     if ($replyTo = $parsedMessage->getReplyTo()) {
         $message->setReplyTo($replyTo);
     }
     // handle subject with default
     if ($subject = $parsedMessage->getSubject()) {
         $message->setSubject($subject);
     }
     // handle body, no default values here
     $message->setBody($parsedMessage->getMessageText());
     if ($parsedMessage->getMessageHtml()) {
         $message->addPart($parsedMessage->getMessageHtml(), 'text/html');
     }
     return $message;
 }
开发者ID:sgomez,项目名称:SystemMailBundle,代码行数:40,代码来源:SwiftMailer.php

示例15: send

 /**
  * Send an email to a number of recipients
  * Returns the number of successful recipients, or FALSE on failure
  * @param mixed The recipients to send to.  One of string, array, 2-dimensional array or Swift_Address
  * @param mixed The address to send from. string or Swift_Address
  * @param string The message subject
  * @param string The message body, optional
  * @return int
  */
 function send($recipients, $from, $subject, $body = null)
 {
     $this->addTo($recipients);
     $sender = false;
     if (is_string($from)) {
         $sender = $this->stringToAddress($from);
     } elseif (is_a($from, "Swift_Address")) {
         $sender =& $from;
     }
     if (!$sender) {
         return false;
     }
     $this->message->setSubject($subject);
     if ($body) {
         $this->message->setBody($body);
     }
     $sent = 0;
     Swift_Errors::expect($e, "Swift_ConnectionException");
     if (!$this->exactCopy && !$this->recipients->getCc() && !$this->recipients->getBcc()) {
         $sent = $this->swift->batchSend($this->message, $this->recipients, $sender);
     } else {
         $sent = $this->swift->send($this->message, $this->recipients, $sender);
     }
     if (!$e) {
         Swift_Errors::clear("Swift_ConnectionException");
         if ($this->autoFlush) {
             $this->flush();
         }
         return $sent;
     }
     $this->setError("Sending failed:<br />" . $e->getMessage());
     return false;
 }
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:42,代码来源:EasySwift.php


注:本文中的Swift_Message::setBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。