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


PHP Swift_Message::setFrom方法代码示例

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


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

示例1: populateMessage

 /**
  * Fills in message using blocks from a template (`body`, `subject`, `from`).
  * If there is no `body` block then whole template will be used.
  * If there is no `subject` or `from` block then corresponding default value will be used.
  * @param \Swift_Message $message
  * @param \Twig_Template $templateContent
  * @param array $data
  */
 protected function populateMessage(\Swift_Message $message, \Twig_Template $templateContent, $data)
 {
     $body = $templateContent->hasBlock('body') ? $templateContent->renderBlock('body', $data) : $templateContent->render($data);
     $subject = $templateContent->hasBlock('subject') ? $templateContent->renderBlock('subject', $data) : $this->defaultSubject;
     $from = $templateContent->hasBlock('from') ? $templateContent->renderBlock('from', $data) : $this->defaultFrom;
     $message->setFrom($from)->setSubject($subject)->setBody($body, 'text/html', 'utf-8');
 }
开发者ID:syzygymsu,项目名称:syzygy-framework-bundle,代码行数:15,代码来源:Composer.php

示例2: 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

示例3: __construct

 public function __construct()
 {
     $this->registry = Registry::getInstance();
     $this->mailerConfig = $this->registry->config->getMailer();
     $this->message = \Swift_Message::newInstance();
     echo $this->mailerConfig->getSender() . PHP_EOL;
     $this->message->setFrom($this->mailerConfig->getSender());
     $this->transport = \Swift_SmtpTransport::newInstance($this->mailerConfig->getHost(), $this->mailerConfig->getPort(), 'ssl')->setUsername($this->mailerConfig->getUser())->setPassword($this->mailerConfig->getPass());
     parent::__construct($this->transport);
 }
开发者ID:sudevva,项目名称:parser2,代码行数:10,代码来源:Mailer.php

示例4: __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

示例5: 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

示例6: 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

示例7: testSend

 public function testSend()
 {
     $message = new Swift_Message();
     $message->setFrom('johnny5@example.com', 'Johnny #5');
     $message->setSubject('Is alive!');
     $message->addTo('you@example.com', 'A. Friend');
     $message->addTo('you+two@example.com');
     $message->addCc('another+1@example.com');
     $message->addCc('another+2@example.com', 'Extra 2');
     $message->addBcc('another+3@example.com');
     $message->addBcc('another+4@example.com', 'Extra 4');
     $message->addPart('<q>Help me Rhonda</q>', 'text/html');
     $message->addPart('Doo-wah-ditty.', 'text/plain');
     $attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
     $attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
     $attachment2->setDisposition('inline');
     $message->attach($attachment);
     $message->attach($attachment2);
     $message->setPriority(1);
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-PM-Tag', 'movie-quotes');
     $messageId = $headers->get('Message-ID')->getId();
     $transport = new PostmarkTransportStub('TESTING_SERVER');
     $client = $this->getMock('GuzzleHttp\\Client', array('request'));
     $transport->setHttpClient($client);
     $o = PHP_OS;
     $v = phpversion();
     $client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <johnny5@example.com>', 'To' => '"A. Friend" <you@example.com>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <another+2@example.com>', 'Bcc' => 'another+3@example.com,"Extra 4" <another+4@example.com>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]]));
     $transport->send($message);
 }
开发者ID:wildbit,项目名称:swiftmailer-postmark,代码行数:30,代码来源:TransportTest.php

示例8: 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

示例9: send

 /**
  * Sends the digest
  */
 public function send()
 {
     $lastMonths = new \DateTime();
     $lastMonths->modify('-6 month');
     $parameters = array('modified_at >= ?0 AND digest = "Y" AND notifications <> "N"', 'bind' => array($lastMonths->getTimestamp()));
     $users = array();
     foreach (Users::find($parameters) as $user) {
         if ($user->email && strpos($user->email, '@') !== false && strpos($user->email, '@users.noreply.github.com') === false) {
             $users[trim($user->email)] = $user->name;
         }
     }
     $fromName = $this->config->mail->fromName;
     $fromEmail = $this->config->mail->fromEmail;
     $url = $this->config->site->url;
     $subject = 'Top Stories from Phosphorum ' . date('d/m/y');
     $lastWeek = new \DateTime();
     $lastWeek->modify('-1 week');
     $order = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - ' . 'IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies + IF(accepted_answer = "Y", 10, 0) DESC';
     $parameters = array('created_at >= ?0 AND deleted != 1 AND categories_id <> 4', 'bind' => array($lastWeek->getTimestamp()), 'order' => $order, 'limit' => 10);
     $e = $this->escaper;
     $content = '<html><head></head><body><p><h1 style="font-size:22px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;padding:16px 0;border-bottom:1px solid #e2e2e2">Top Stories from Phosphorum</h1></p>';
     foreach (Posts::find($parameters) as $post) {
         $user = $post->user;
         if ($user == false) {
             continue;
         }
         $content .= '<p><a style="text-decoration:none;display:block;font-size:20px;color:#333;letter-spacing:-0.5px;line-height:1.25;font-weight:normal;color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">' . $e->escapeHtml($post->title) . '</a></p>';
         $content .= '<p><table width="100%"><td><table><tr><td>' . '<img src="https://secure.gravatar.com/avatar/' . $user->gravatar_id . '?s=32&amp;r=pg&amp;d=identicon" width="32" height="32" alt="' . $user->name . ' icon">' . '</td><td><a style="text-decoration:none;color:#155fad" href="' . $url . '/user/' . $user->id . '/' . $user->login . '">' . $user->name . '<br><span style="text-decoration:none;color:#999;text-decoration:none">' . $user->getHumanKarma() . '</span></a></td></tr></table></td><td align="right"><table style="border: 1px solid #dadada;" cellspacing=5>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Created</label><br>' . $post->getHumanCreatedAt() . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Replies</label><br>' . $post->number_replies . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Views</label><br>' . $post->number_views . '</td>' . '<td align="center"><label style="color:#999;margin:0px;font-weight:normal;">Votes</label><br>' . ($post->votes_up - $post->votes_down) . '</td>' . '</tr></table></td></tr></table></p>';
         $content .= $this->markdown->render($e->escapeHtml($post->content));
         $content .= '<p><a style="color:#155fad" href="' . $url . '/discussion/' . $post->id . '/' . $post->slug . '">Read more</a></p>';
         $content .= '<hr style="border: 1px solid #dadada">';
     }
     $textContent = strip_tags($content);
     $htmlContent = $content . '<p style="font-size:small;-webkit-text-size-adjust:none;color:#717171;">';
     $htmlContent .= PHP_EOL . 'This email was sent by Phalcon Framework. Change your e-mail preferences <a href="' . $url . '/settings">here</a></p>';
     foreach ($users as $email => $name) {
         try {
             $message = new \Swift_Message('[Phalcon Forum] ' . $subject);
             $message->setTo(array($email => $name));
             $message->setFrom(array($fromEmail => $fromName));
             $bodyMessage = new \Swift_MimePart($htmlContent, 'text/html');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             $bodyMessage = new \Swift_MimePart($textContent, 'text/plain');
             $bodyMessage->setCharset('UTF-8');
             $message->attach($bodyMessage);
             if (!$this->transport) {
                 $this->transport = \Swift_SmtpTransport::newInstance($this->config->smtp->host, $this->config->smtp->port, $this->config->smtp->security);
                 $this->transport->setUsername($this->config->smtp->username);
                 $this->transport->setPassword($this->config->smtp->password);
             }
             if (!$this->mailer) {
                 $this->mailer = \Swift_Mailer::newInstance($this->transport);
             }
             $this->mailer->send($message);
         } catch (\Exception $e) {
             echo $e->getMessage(), PHP_EOL;
         }
     }
 }
开发者ID:woyifang,项目名称:forum,代码行数:63,代码来源:Digest.php

示例10: send

 /**
  * {@inheritdoc}
  */
 public function send($from, $to, $subject, $body, $replyTo = null, $attachments = [])
 {
     $message = new \Swift_Message($subject, $body);
     // set from and to
     $message->setFrom($from);
     $message->setTo($to);
     // set attachments
     if (count($attachments) > 0) {
         foreach ($attachments as $file) {
             if ($file instanceof \SplFileInfo) {
                 $path = $file->getPathName();
                 $name = $file->getFileName();
                 // if uploadedfile get original name
                 if ($file instanceof UploadedFile) {
                     $name = $file->getClientOriginalName();
                 }
                 $message->attach(\Swift_Attachment::fromPath($path)->setFilename($name));
             }
         }
     }
     // set replyTo
     if ($replyTo != null) {
         $message->setReplyTo($replyTo);
     }
     return $this->mailer->send($message);
 }
开发者ID:alexander-schranz,项目名称:sulu-website-user-bundle,代码行数:29,代码来源:MailHelper.php

示例11: 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

示例12: send

 /**
  * @param $cname     string       Config key from config/email.php
  * @param $subject   string       Message subject
  * @param $body      string       Message body
  * @param $from      string|array From single address (for example 'user@domain.tld' or array('user@domain.tld' => 'John Doe'))
  * @param $to        string|array To single address (for example 'user@domain.tld' or array('user@domain.tld' => 'John Doe'))
  * @param $mime_type string       Message MIME type, default value text/plain
  * @param $charset   string       Message character set, default value UTF-8
  * 
  * @return int Result code
  */
 public static function send($cname, $subject, $body, $from, $to, $mime_type = 'text/plain', $charset = 'utf-8')
 {
     $mailer = self::instance($cname);
     $message = new Swift_Message($subject, $body, $mime_type, $charset);
     $message->setFrom($from)->setTo($to);
     return $mailer->send($message);
 }
开发者ID:shanmuvel,项目名称:kohana,代码行数:18,代码来源:Email.php

示例13: 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

示例14: sendEmail

 public function sendEmail($recipient_name, $recipient_email, $subject, $body)
 {
     //$subject = 'Hello from Mandrill, PHP!';
     $from = array($this::SENDER_EMAIL => $this::SENDER_NAME);
     $to = array($recipient_email => $recipient_name);
     //$text = "Mandrill speaks plaintext";
     //$html = "<em>Mandrill speaks <strong>HTML</strong></em>";
     $transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587);
     $transport->setUsername($this::MANDRILL_USERNAME);
     $transport->setPassword($this::MANDRILL_PASSWORD);
     $swift = Swift_Mailer::newInstance($transport);
     $message = new Swift_Message($subject);
     $message->setFrom($from);
     //$message->setBody($html, 'text/html');
     $message->setTo($to);
     $message->addPart($body, 'text/plain');
     $failures = '';
     if ($recipients = $swift->send($message, $failures)) {
         echo 'Message successfully sent!';
         return true;
     } else {
         echo "There was an error:\n";
         print_r($failures);
         return false;
     }
 }
开发者ID:gabgitt,项目名称:voting,代码行数:26,代码来源:MandrillEmail.php

示例15: __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


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