本文整理汇总了PHP中Swift_Mailer::createMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Mailer::createMessage方法的具体用法?PHP Swift_Mailer::createMessage怎么用?PHP Swift_Mailer::createMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Mailer
的用法示例。
在下文中一共展示了Swift_Mailer::createMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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')));
}
示例3: 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);
}
示例4: 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;
}
示例5: 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);
}
}
示例6: notify
/**
* @param Rfc $rfc
* @param array $voteDiff
*/
public function notify(Rfc $rfc, array $voteDiff)
{
foreach ($this->emailSubscriberRepository->findAll() as $subscriber) {
$email = $this->twig->render('rfc.twig', ['rfcName' => $rfc->getName(), 'details' => $voteDiff['details'], 'changeLog' => $voteDiff['changeLog'], 'voteDiffs' => $voteDiff['votes'], 'rfcVotes' => $rfc->getVotes(), 'unsubscribeUrl' => sprintf('%s/unsubscribe/%s', $this->config->get('app.url'), $subscriber->getUnsubscribeToken())]);
$message = $this->mailer->createMessage()->setSubject(sprintf('%s updated!', $rfc->getName()))->setFrom('notifier@php-rfc-digestor.com')->setTo($subscriber->getEmail())->setBody($email, 'text/html');
$this->mailer->send($message);
}
}
示例7: sendAttributeSupportMail
public function sendAttributeSupportMail()
{
$user = $this->userService->getUser();
$body = $this->templateEngine->render('OpenConextProfileBundle:AttributeSupport:email.html.twig', ['attributes' => $user->getAttributes()]);
/** @var Message $message */
$message = $this->mailer->createMessage();
$message->setFrom($this->mailFrom->getEmailAddress())->setTo($this->mailTo->getEmailAddress())->setSubject(sprintf('Personal debug info of %s', $user->getId()))->setBody($body, 'text/html', 'utf-8');
$this->mailer->send($message);
}
示例8: createMessage
/**
* @param $subject
* @param $template
* @param $data
* @param Request $request
* @return mixed
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
* @throws \Exception
* @throws \Twig_Error
*
* @return \Swift_Message
*/
public function createMessage($subject, $template, $data, Request $request = null)
{
$history = null;
if ($request && $request->cookies->has('tracker_id')) {
/** @var \keltanas\Bundle\TrackingBundle\Entity\History $history */
$history = $this->em->find('keltanasTrackingBundle:History', $request->cookies->get('tracker_id'));
}
$message = $this->mailer->createMessage()->setSubject($subject)->setFrom($this->from)->setTo($this->to)->setBody($this->templating->render($template, ['data' => $data, 'history' => $history]), 'text/html', 'utf-8');
return $message;
}
示例9: sendEmail
/**
* @param \Sonata\NotificationBundle\Model\MessageInterface $message
*/
private function sendEmail(MessageInterface $message)
{
$mail = $this->mailer->createMessage()->setSubject($message->getValue('subject'))->setFrom(array($message->getValue(array('from', 'email')) => $message->getValue(array('from', 'name'))))->setTo($message->getValue('to'));
if ($text = $message->getValue(array('message', 'text'))) {
$mail->addPart($text, 'text/plain');
}
if ($html = $message->getValue(array('message', 'html'))) {
$mail->addPart($html, 'text/html');
}
$this->mailer->send($mail);
}
示例10: sendResetEmail
/**
* Sends reset email
* @param string $email
* @param string $activationHash
* @return void
*/
public function sendResetEmail($email, $activationHash)
{
/** @var \Swift_Message $confirmation */
$confirmation = $this->mailer->createMessage();
$confirmation->setSubject('Reset your password');
$confirmation->setFrom($this->senderEmail);
$confirmation->setTo($email);
$confirmation->setReplyTo($this->senderEmail);
$confirmation->setBody($this->twig->render($this->txtTwigTemplate, array('activation_hash' => $activationHash)), 'text/plain');
$confirmation->addPart($this->twig->render($this->htmlTwigTemplate, array('activation_hash' => $activationHash)), 'text/html');
$this->mailer->send($confirmation);
}
示例11: send
/**
* Sends a mail.
*
* @ParamType("message", type="Abc\Bundle\JobBundle\Job\Mailer\Message")
* @ParamType("logger", type="@abc.logger")
*
* @param Message $message
* @param LoggerInterface $logger
* @throws \Exception Rethrows exceptions thrown by mailer
*/
public function send(Message $message, LoggerInterface $logger)
{
$logger->debug('Send mail {message}', array('message' => $message));
$mail = $this->mailer->createMessage()->setSubject($message->getSubject())->setFrom($message->getFrom())->setTo($message->getTo());
$mail->addPart($message->getMessage(), 'text/plain');
try {
$this->mailer->send($mail);
$this->mailer->getTransport()->stop();
} catch (\Exception $e) {
$this->mailer->getTransport()->stop();
throw $e;
}
}
示例12: message
/**
* @param Notification $notification
*
* @return \Swift_Message
*/
private function message(Notification $notification)
{
/** @var \Swift_Message $message */
$message = $this->mailer->createMessage();
$message->setSubject(ucfirst($notification->getHeaderText()));
$senderName = $this->configManager->get('oro_notification.email_notification_sender_name');
$message->setFrom($this->senderEmail, $senderName);
$mail = $notification->getAuthor()->getEmail();
$message->setTo($mail);
$options = array('user' => $this->getFormattedUserName($notification), 'header' => $notification->getHeaderText());
$txtTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_TXT);
$htmlTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_HTML);
$message->setBody($this->twig->render($txtTemplate, $options), 'text/plain');
$message->addPart($this->twig->render($htmlTemplate, $options), 'text/html');
return $message;
}
示例13: 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('walter.tamboer@live.com', '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;
}
示例14: notify
/**
* {@inheritdoc}
*/
public function notify(JobExecution $jobExecution)
{
if (null === ($email = $this->getEmail())) {
return;
}
$parameters = array('jobExecution' => $jobExecution, 'log' => $this->logger->getFilename());
$txtBody = $this->twig->render('AkeneoBatchBundle:Mails:notification.txt.twig', $parameters);
$htmlBody = $this->twig->render('AkeneoBatchBundle:Mails:notification.html.twig', $parameters);
$message = $this->mailer->createMessage();
$message->setSubject('Job has been executed');
$message->setFrom($this->senderEmail);
$message->setTo($email);
$message->setBody($txtBody, 'text/plain');
$message->addPart($htmlBody, 'text/html');
$this->mailer->send($message);
}
示例15: sendPassword
/**
* @param User $user
* @param $plainPassword
*
* @return array|bool
*/
public function sendPassword(User $user, $plainPassword)
{
/* @var \Swift_Message $message */
$message = $this->mailer->createMessage();
$locale = $this->getLocale($user);
$subject = T::trans('Your password', array(), 'mail', $locale);
$body = T::trans('Your new password is: %plainPassword%', array('%plainPassword%' => $plainPassword), 'mail', $locale);
$message->setFrom($this->mailSender);
$message->setTo($user->getEmail());
$message->setSubject($subject);
$message->setBody($body);
$failedRecipients = array();
if (!$this->mailer->send($message, $failedRecipients)) {
return $failedRecipients;
}
return true;
}