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


PHP Swift_Mailer::send方法代码示例

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


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

示例1: process

 /**
  * Process email model sending.
  *
  * @param EmailModel $model
  * @return Email
  * @throws \Swift_SwiftException
  */
 public function process(EmailModel $model)
 {
     $this->assertModel($model);
     $messageDate = new \DateTime('now', new \DateTimeZone('UTC'));
     /** @var \Swift_Message $message */
     $message = $this->mailer->createMessage();
     $message->setDate($messageDate->getTimestamp());
     $message->setFrom($this->getAddresses($model->getFrom()));
     $message->setTo($this->getAddresses($model->getTo()));
     $message->setSubject($model->getSubject());
     $message->setBody($model->getBody(), $model->getType() === 'html' ? 'text/html' : 'text/plain');
     $messageId = $message->generateId();
     if (!$this->mailer->send($message)) {
         throw new \Swift_SwiftException('An email was not delivered.');
     }
     $origin = $this->getEmailOrigin($model->getFrom());
     $this->emailEntityBuilder->setOrigin($origin);
     $email = $this->emailEntityBuilder->email($model->getSubject(), $model->getFrom(), $model->getTo(), $messageDate, $messageDate, $messageDate);
     $email->addFolder($origin->getFolder(FolderType::SENT));
     $email->setEmailBody($this->emailEntityBuilder->body($model->getBody(), $model->getType() === 'html', true));
     $email->setMessageId($messageId);
     // persist the email and all related entities such as folders, email addresses etc.
     $this->emailEntityBuilder->getBatch()->persist($this->getEntityManager());
     // associate the email with the target entity if exist
     if ($model->hasEntity()) {
         $targetEntity = $this->doctrineHelper->getEntity($model->getEntityClass(), $model->getEntityId());
         if ($targetEntity) {
             $this->emailActivityManager->addAssociation($email, $targetEntity);
         }
     }
     // flush all changes to the database
     $this->getEntityManager()->flush();
     return $email;
 }
开发者ID:xamin123,项目名称:platform,代码行数:41,代码来源:Processor.php

示例2: sendMail

 /**
  * Sends an email
  *
  * @param string $recipient
  * @param string $templatePath Path to the twig template
  * @param array $data
  * @param array $blindCopyRecipients Recipients to send bcc
  *
  * @return bool
  */
 public function sendMail($recipient, $templatePath, $data = array(), $blindCopyRecipients = array())
 {
     $tmplData = array_merge($data, array('footerTxt' => $this->templateFooterTxtPath, 'footerHtml' => $this->templateFooterHtmlPath));
     // Load template from twig.
     $template = $this->twig->loadTemplate($templatePath);
     // Merge twig globals so that they also are available in renderBlock.
     $tmplData = $this->twig->mergeGlobals($tmplData);
     // Get subject from block.
     $subject = $template->renderBlock('subject', $tmplData);
     $emailBodyText = $template->renderBlock('body_text', $tmplData);
     $emailBodyHtml = $template->renderBlock('body_html', $tmplData);
     /** @var \Swift_Message $message */
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->emailFrom)->setTo($recipient)->setBody($emailBodyText, 'text/plain')->addPart($emailBodyHtml, 'text/html');
     // add blind copy recipients
     foreach ($blindCopyRecipients as $bcc) {
         $message->addBcc($bcc);
     }
     $failedRecipients = array();
     $this->mailer->send($message, $failedRecipients);
     if (count($failedRecipients) > 0) {
         $this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));
         return false;
     }
     return true;
 }
开发者ID:sulu,项目名称:sulu-sales,代码行数:35,代码来源:EmailManager.php

示例3: execute

 /**
  * Execute Command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $email = $this->twig->render('test.twig');
     $message = $this->mailer->createMessage()->setSubject('PHP RFC Digestor Test Email')->setFrom('notifier@php-rfc-digestor.com')->setTo($input->getArgument('email'))->setBody($email, 'text/html');
     $this->mailer->send($message);
     $output->writeln(sprintf('<info>Email sent to %s</info>', $input->getArgument('email')));
 }
开发者ID:shakyShane,项目名称:php-rfc-digestor,代码行数:13,代码来源:Email.php

示例4: sendMail

 /**
  * @param \Swift_Message|Mail $mail
  */
 public function sendMail($mail)
 {
     if (!$mail instanceof \Swift_Message) {
         $mail = $mail->createSwitfMessage();
     }
     $this->mailer->send($mail);
 }
开发者ID:nuxia,项目名称:nuxia-plugin,代码行数:10,代码来源:Mailer.php

示例5: send

 /**
  * Transport a message.
  *
  * @param MessageInterface $message
  *
  * @return TransportStatus
  */
 public function send(MessageInterface $message)
 {
     $email = $this->renderer->renderMessage($message);
     $failedRecipients = array();
     $successfullySendCount = $this->swiftMailer->send($email, $failedRecipients);
     return new TransportStatus($message, $successfullySendCount, $failedRecipients);
 }
开发者ID:avisota,项目名称:core,代码行数:14,代码来源:AbstractSwiftTransport.php

示例6: sendConfirmMail

 private function sendConfirmMail(Configuration $configuration, ContactInterface $model)
 {
     $text = $this->templating->render($configuration->getConfirmTemplate(), ['data' => $model]);
     $subject = $this->translator->trans($configuration->getSubject(), [], $configuration->getTranslationDomain());
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($configuration->getFrom())->setTo($model->getEmail())->setBody($text, 'text/html');
     $this->mailer->send($message);
 }
开发者ID:enhavo,项目名称:enhavo,代码行数:7,代码来源:ContactMailer.php

示例7: deliver

 /**
  * Delivers an email
  *
  * @param  MailInterface $mail
  * @param  Boolean       $readReceipt
  * @return int           the number of messages that have been sent
  *
  * @throws LogicException In case no Receiver provided
  * @throws LogicException In case a read-receipt is asked but no Emitter provided
  */
 public function deliver(MailInterface $mail, $readReceipt = false, array $attachments = null)
 {
     if (!$mail->getReceiver()) {
         throw new LogicException('You must provide a receiver for a mail notification');
     }
     $message = \Swift_Message::newInstance($this->prefix . $mail->getSubject(), $mail->renderHTML(), 'text/html', 'utf-8');
     $message->addPart($mail->getMessage(), 'text/plain', 'utf-8');
     $message->setFrom($this->emitter->getEmail(), $this->emitter->getName());
     $message->setTo($mail->getReceiver()->getEmail(), $mail->getReceiver()->getName());
     if ($mail->getEmitter()) {
         $message->setReplyTo($mail->getEmitter()->getEmail(), $mail->getEmitter()->getName());
     }
     if (is_array($attachments)) {
         foreach ($attachments as $attachment) {
             $message->attach($attachment->As_Swift_Attachment());
         }
     }
     if ($readReceipt) {
         if (!$mail->getEmitter()) {
             throw new LogicException('You must provide an emitter for a ReadReceipt');
         }
         $message->setReadReceiptTo([$mail->getEmitter()->getEmail() => $mail->getEmitter()->getName()]);
     }
     if (!$this->mailer->getTransport()->isStarted()) {
         $this->mailer->getTransport()->start();
     }
     $ret = $this->mailer->send($message);
     $this->mailer->getTransport()->stop();
     $this->dispatcher->dispatch('phraseanet.notification.sent');
     return $ret;
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:41,代码来源:Deliverer.php

示例8: send

 /**
  * @throws \Swift_DependencyException
  *
  * @return int
  */
 public function send()
 {
     if ($this->message === null) {
         throw new \Swift_DependencyException('First you need to access method "createMailMessage"');
     }
     return $this->mailer->send($this->message);
 }
开发者ID:kisphp,项目名称:simple-mail,代码行数:12,代码来源:Messenger.php

示例9: sendMail

 public function sendMail(\Exception $exception, Request $request, array $context, $needToFlush)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     if (!$this->_hasInitialized) {
         $this->_initialize();
     }
     $params = array('exception' => $exception, 'request' => $request, 'context' => $context, 'status_text' => Response::$statusTexts[$exception->getStatusCode()]);
     $preMailEvent = new GenericEvent($params, array('shouldSend' => true));
     $this->_eventDispatcher->dispatch('ehough.bundle.emailErrors.preMail', $preMailEvent);
     if (!$preMailEvent->getArgument('shouldSend')) {
         //mail was cancelled
         return;
     }
     $body = $this->_templatingEngine->render('EhoughEmailErrorsBundle::mail.html.twig', $params);
     $subject = '[' . $request->headers->get('host') . '] Error ' . $exception->getStatusCode() . ': ' . $exception->getMessage();
     if (function_exists('mb_substr')) {
         $subject = mb_substr($subject, 0, 255);
     } else {
         $subject = substr($subject, 0, 255);
     }
     $mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->_fromAddress)->setTo($this->_toAddress)->setContentType('text/html')->setBody($body);
     $this->_mailer->send($mail);
     if ($needToFlush) {
         $this->_flushEmailer();
     }
 }
开发者ID:ehough,项目名称:emailerrors-bundle,代码行数:28,代码来源:Mailer.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: 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

示例12: send

 /**
  * Send an email!
  *
  * @param string $message  HTML Content with the message(body)
  * @param string $callback Callback function to act on the message
  */
 public function send($htmlMessage, $callback)
 {
     $message = $this->createMessage();
     $this->callMessageBuilder($callback, $message);
     $message->setBody($htmlMessage, 'text/html');
     return $this->swift->send($message->getSwiftMessage());
 }
开发者ID:anekdotes,项目名称:mailer,代码行数:13,代码来源:SwiftMailerAdapter.php

示例13: postUpdate

 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $this->mailer = $this->container->get('mailer');
     $this->mailerHelper = $this->container->get('stfalcon_event.mailer_helper');
     $this->pdfGeneratorHelper = $this->container->get('stfalcon_event.pdf_generator.helper');
     if ($entity instanceof Payment) {
         if ($entity->getStatus() === Payment::STATUS_PAID) {
             $tickets = $this->container->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Ticket')->getAllTicketsByPayment($entity);
             /** @var Ticket $ticket */
             foreach ($tickets as $ticket) {
                 /** @var $user User */
                 $user = $ticket->getUser();
                 /** @var Event $event */
                 $event = $ticket->getEvent();
                 $successPaymentTemplateContent = $this->mailerHelper->renderTwigTemplate('StfalconEventBundle:Interkassa:_mail.html.twig', ['user' => $user, 'event' => $event]);
                 $mail = new Mail();
                 $mail->addEvent($event);
                 $mail->setText($successPaymentTemplateContent);
                 $html = $this->pdfGeneratorHelper->generateHTML($ticket);
                 $message = $this->mailerHelper->formatMessage($user, $mail);
                 $message->setSubject($event->getName())->attach(\Swift_Attachment::newInstance($this->pdfGeneratorHelper->generatePdfFile($ticket, $html), $ticket->generatePdfFilename()));
                 $this->mailer->send($message);
             }
         }
     }
 }
开发者ID:bolotyuh,项目名称:fwdays,代码行数:27,代码来源:PaymentListener.php

示例14: flush

 /**
  * Flushes messages
  */
 public function flush()
 {
     foreach ($this->pendingEmails as $email) {
         $message = \Swift_Message::newInstance()->setSubject($this->translator->trans($email->getSubject()))->setFrom($this->from)->setTo($email->getSendTo())->setBody($this->templating->render($email->getTemplate(), $email->getData()));
         $this->mailer->send($message, $failedRecipients);
     }
     $this->clear();
 }
开发者ID:Valentinlazy,项目名称:symfony-angular-seed,代码行数:11,代码来源:Messenger.php

示例15: send

 /**
  * @param string|array $to
  * @param MailTemplate $template
  * @param array $data
  */
 private function send($to, MailTemplate $template, array $data = [])
 {
     $body = $this->render($template, $data);
     $message = new \Swift_Message($template->getSubject(), $body, "text/html", "utf8");
     $message->setFrom($this->sender);
     $message->setTo($to);
     $this->mailer->send($message);
 }
开发者ID:vaidasif,项目名称:symfony-force,代码行数:13,代码来源:Mailer.php


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