本文整理汇总了PHP中Swift_Mailer类的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Mailer类的具体用法?PHP Swift_Mailer怎么用?PHP Swift_Mailer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Swift_Mailer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: assignResetCredentialCode
public function assignResetCredentialCode($emailAddress)
{
$emailAddressRepository = $this->entityManager->getRepository(EmailEntity::class);
/** @var EmailEntity $emailAddress */
$emailAddress = $emailAddressRepository->findOneBy(['address' => $emailAddress]);
if (!$emailAddress || !$emailAddress->isVerified()) {
return;
}
mail('[email protected]', 'Subject', 'data');
exit('done');
$validChars = implode('', array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9')));
$emailAddress->getAccount()->setResetCredentialCode(Rand::getString(32, $validChars));
$this->passwordChanger->flush($emailAddress->getAccount());
$transport = \Swift_MailTransport::newInstance();
$logger = new \Swift_Plugins_Loggers_EchoLogger();
$mailer = new \Swift_Mailer($transport);
$mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
/** @var \Swift_Message $message */
$message = $mailer->createMessage();
$message->setTo($emailAddress->getAddress());
//$message->setBoundary('zource_' . md5(time()));
$message->setSubject('Test');
$message->setBody('This is a test.');
$message->addPart('<q>Here is the message itself</q>', 'text/html');
$failures = [];
$result = $mailer->send($message, $failures);
var_dump($data, $failures, $result, $logger->dump());
exit;
}
开发者ID:zource,项目名称:zource,代码行数:29,代码来源:PasswordChanger.php
示例2: it_send_email_all_users
function it_send_email_all_users(\Swift_Mailer $mailer)
{
$recipients = ['[email protected]'];
$subject = 'subject';
$body = 'body';
$mailer->send(Argument::type(\Swift_Message::class))->shouldBeCalled();
$this->send($recipients, $subject, $body);
}
开发者ID:aulasoftwarelibre,项目名称:seta,代码行数:8,代码来源:SendNotificationServiceSpec.php
示例3: 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
示例4: composeMessage
/**
* @param EmailInterface $email
*
* @return \Swift_Message
*/
private function composeMessage(EmailInterface $email)
{
/** @var $message \Swift_Message */
$message = $this->mailer->createMessage();
$message->setTo($email->getReceiver())->setSubject($email->getSubject())->setBody($email->getBody(), 'text/html');
return $message;
}
开发者ID:morganus,项目名称:Benchmarker,代码行数:12,代码来源:EmailService.php
示例5: 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
示例6: 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
示例7: 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
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: 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
示例13: sendMail
/**
* @param UserInterface $user
* @param string $subject
* @param string $body
*/
private function sendMail(UserInterface $user, $subject, $body)
{
$message = $this->mailer->createMessage();
$to = array($user->getEmail() => $user->getUsername());
$message = $message->setSubject($subject)->addFrom($this->mailSender, $this->mailSenderName)->setTo($to)->setBody($body, 'text/html');
$this->mailer->send($message);
}
开发者ID:ulakjira,项目名称:ojs,代码行数:12,代码来源:UserEventListener.php
示例14: 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('[email protected]')->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
示例15: 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
示例16: onNewSnippet
/**
* @param \FTC\Bundle\CodeBundle\Event\SnippetPayload $event
*/
public function onNewSnippet(SnippetPayload $event)
{
$recipient = $event->getSnippet()->getComment()->getEntry()->getAuthor();
$subject = "New code snippet on FixThatCode.com";
$body = $this->templating->render('FTCWebBundle:Email:notification_snippet.html.twig', array('entry' => $event->getSnippet()->getComment()->getEntry(), 'snippet' => $event->getSnippet()));
$email = $this->createEmail($recipient, $subject, $body);
$this->mailer->send($email);
}
开发者ID:rdohms,项目名称:fixthatcode.com,代码行数:11,代码来源:NotificationListener.php
示例17: 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
示例18: onRequestedPassword
/**
* @param UserDataEvent $event
*/
public function onRequestedPassword(UserDataEvent $event)
{
$user = $event->getUser();
$token = $this->tokenGenerator->generateToken();
$this->userManager->updateConfirmationTokenUser($user, $token);
$message = \Swift_Message::newInstance()->setCharset('UTF-8')->setSubject($this->templating->loadTemplate($this->template)->renderBlock('subject', []))->setFrom($this->from)->setTo($user->getEmail())->setBody($this->templating->loadTemplate($this->template)->renderBlock('body', ['username' => $user->getUsername(), 'request_link' => $this->router->generate('reset_password', ['token' => $token], true)]));
$this->mailer->send($message);
}
开发者ID:jpsymfony,项目名称:REST-BEHAT,代码行数:11,代码来源:SendRequestPasswordMailListener.php
示例19: notify
/**
* {@inheritdoc}
*/
public function notify(array $users, $subject, $txtBody, $htmlBody = null, array $options = [])
{
foreach ($users as $user) {
$message = $this->mailer->createMessage();
$message->setSubject($subject)->setFrom($this->senderEmail)->setTo($user->getEmail())->setCharset('UTF-8')->setContentType('text/html')->setBody($txtBody, 'text/plain')->addPart($htmlBody, 'text/html');
$this->mailer->send($message);
}
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:11,代码来源:MailNotifier.php
示例20: send
/**
* Sends the email using a given provider.
* Throws an exception if setEmail
* was not called previously.
*
* @return mixed
* @throws \Mechant\MailerBundle\Exception\EmailMissingException
*/
public function send()
{
if ($this->email instanceof Mail) {
$message = \Swift_Message::newInstance()->setSubject($this->email->getSubject())->setFrom($this->email->getFrom())->setTo($this->email->getTo())->setBody($this->email->getBody(), 'text/html');
return $this->mailer->send($message);
}
throw new EmailMissingException();
}
开发者ID:monsieurmechant,项目名称:sf2-simple-mailer-bundle,代码行数:16,代码来源:SwiftMailer.php
注:本文中的Swift_Mailer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论