コード例 #1
0
 /**
  * Add a recipient to the message.
  *
  * @param  string|array  $address
  * @param  string|null  $name
  * @param  bool  $override
  * @return $this
  */
 public function to($address, $name = null, $override = false)
 {
     if ($override) {
         return $this->swift->setTo($address, $name);
     }
     return $this->addAddresses($address, $name, 'To');
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
ファイル: Mailer.php プロジェクト: sudevva/parser2
 public function setGroup($name)
 {
     $mailTo = $this->mailerConfig->getMailToByGroupName($name);
     if ($mailTo) {
         $this->message->setTo($mailTo->getMailTo());
         return true;
     }
     return false;
 }
コード例 #4
0
ファイル: Smtp.php プロジェクト: vzoom96/Hackathon-Projects
 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;
 }
コード例 #5
0
 /**
  * @When I send email to :email with message :body
  */
 public function iSendEmailWithMessage($email, $body)
 {
     $message = new \Swift_Message('Subject', $body);
     $message->setSender('*****@*****.**');
     $message->setTo($email);
     $this->sendEmail($message);
 }
コード例 #6
0
ファイル: MandrillBot.php プロジェクト: sriramsv/jarvis
 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);
 }
コード例 #7
0
ファイル: EmailModelo.php プロジェクト: netor27/Unova
function sendMailConSendGrid($text, $html, $subject, $from, $to)
{
    include_once "lib/php/swift/swift_required.php";
    $username = '******';
    $password = '******';
    // 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;
}
コード例 #8
0
ファイル: MailSender.php プロジェクト: jvasseur/mail-sender
 /**
  * @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);
 }
コード例 #9
0
ファイル: MandrillEmail.php プロジェクト: gabgitt/voting
 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;
     }
 }
コード例 #10
0
ファイル: UserForgot.php プロジェクト: Monori/imgservice
 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();
             }
         }
     }
 }
コード例 #11
0
ファイル: Mailer.php プロジェクト: citco/mailer
 /**
  * Send a Swift Message instance.
  *
  * @param  \Swift_Message  $message
  * @return int
  */
 protected function sendSwiftMessage($message)
 {
     $from = $message->getFrom();
     if (empty($from)) {
         list($sender_addr, $sender_name) = $this->sender_addr;
         empty($sender_addr) or $message->setFrom($sender_addr, $sender_name);
     }
     list($log_addr, $log_name) = $this->log_addr;
     empty($log_addr) or $message->setBcc($log_addr, $log_name);
     $to = $message->getTo();
     empty($to) or $to = key($to);
     /*
      * Set custom headers for tracking
      */
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-Site-ID', $this->x_site_id);
     $headers->addTextHeader('X-User-ID', base64_encode($to));
     /*
      * Set to address based on environment
      */
     if (strcasecmp($this->environment, 'production') != 0) {
         list($dev_addr, $dev_name) = $this->developer_addr;
         $message->setTo($dev_addr, $dev_name);
     }
     /*
      * Set return path.
      */
     if ($this->return_path) {
         $return_path = $this->generateReturnPathEmail(key($message->getTo()));
         $message->setReturnPath($return_path);
     }
     parent::sendSwiftMessage($message);
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
 /**
  * {@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);
 }
コード例 #14
0
ファイル: Digest.php プロジェクト: woyifang/forum
 /**
  * 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;
         }
     }
 }
コード例 #15
0
ファイル: EmailSender.php プロジェクト: sandeepa91/JMS-V1
 /**
  * @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;
     }
 }
コード例 #16
0
 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;
 }
コード例 #17
0
ファイル: UserReset.php プロジェクト: Monori/imgservice
 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: "******"\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'));
     }
 }
コード例 #18
0
ファイル: Mailer.php プロジェクト: vaidasif/symfony-force
 /**
  * @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);
 }
コード例 #19
0
 /**
  * Send prepared message
  * @return MailerInterface
  */
 public function send()
 {
     if (null === $this->message) {
         throw new PrepareMessageException("Prepare Message first");
     }
     $this->message->setTo($this->getTo())->setFrom($this->getFrom())->setReplyTo($this->getReplyTo());
     $this->mailer->send($this->message);
     return $this;
 }
コード例 #20
0
ファイル: SwiftMailer.php プロジェクト: mpf-soft/app-basic
 /**
  * @param $to
  * @param $from
  * @param $subject
  * @param $message
  * @param $attachaments
  * @param $html
  * @return int
  */
 public function send($to, $from, $subject, $message, $attachaments, $html)
 {
     $mail = new \Swift_Message();
     $mail->setSubject($subject)->setFrom($from['email'], $from['name'])->setReplyTo($from['reply-to']['email'], $from['reply-to']['name'])->setBody($message, $html ? 'text/html' : 'text/plain');
     if (is_array($to)) {
         foreach ($to as $add => $name) {
             if (is_int($add)) {
                 $mail->setTo($name);
             } else {
                 $mail->setTo([$add => $name]);
             }
         }
     }
     foreach ($attachaments as $attachment) {
         $mail->attach(\Swift_Attachment::fromPath($attachment));
     }
     return $this->mailer->send($mail);
 }
コード例 #21
0
ファイル: AuthCodeMailer.php プロジェクト: wallabag/wallabag
 /**
  * Send the auth code to the user via email.
  *
  * @param TwoFactorInterface $user
  */
 public function sendAuthCode(TwoFactorInterface $user)
 {
     $template = $this->twig->loadTemplate('WallabagUserBundle:TwoFactor:email_auth_code.html.twig');
     $subject = $template->renderBlock('subject', []);
     $bodyHtml = $template->renderBlock('body_html', ['user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl, 'wallabag_url' => $this->wallabagUrl]);
     $bodyText = $template->renderBlock('body_text', ['user' => $user->getName(), 'code' => $user->getEmailAuthCode(), 'support_url' => $this->supportUrl]);
     $message = new \Swift_Message();
     $message->setTo($user->getEmail())->setFrom($this->senderEmail, $this->senderName)->setSubject($subject)->setBody($bodyText, 'text/plain')->addPart($bodyHtml, 'text/html');
     $this->mailer->send($message);
 }
コード例 #22
0
ファイル: ResetEmailer.php プロジェクト: cloudtracer/opencfp
 private function preparedMessage($email, $parameters)
 {
     $message = new \Swift_Message();
     $message->setTo($email);
     $message->setFrom($this->template->renderBlock('from', $parameters), $this->template->renderBlock('from_name', $parameters));
     $message->setSubject($this->template->renderBlock('subject', $parameters));
     $message->setBody($this->template->renderBlock('body_text', $parameters));
     $message->addPart($this->template->renderBlock('body_html', $parameters), 'text/html');
     return $message;
 }
コード例 #23
0
    /**
     * Prepare the email message.
     */
    public function processEmail()
    {
        $this->count = 1;
        $mail = new Swift_Message();
        $mail->setContentType('text/plain');
        $mail->setCharset('utf-8');
        if ($this->getOption('use_complete_template', true)) {
            $mail->setBody(sprintf(<<<EOF
------
%s - %s
------
%s
------
EOF
, $this->options['name'], $this->options['email'], $this->options['message']));
        } else {
            $mail->setBody($this->options['message']);
        }
        $mail->setSender(array(sfPlop::get('sf_plop_messaging_from_email') => sfPlop::get('sf_plop_messaging_from_name')));
        $mail->setFrom(array($this->options['email'] => $this->options['name']));
        if ($this->getOption('copy')) {
            $mail->setCc(array($this->options['email'] => $this->options['name']));
            $this->count++;
        }
        if (is_integer($this->getOption('receiver'))) {
            $receiver = sfGuardUserProfilePeer::retrieveByPK($this->getOption('receiver'));
            if ($receiver) {
                $mail->setTo(array($receiver->getEmail() => $receiver->getFullName()));
            } else {
                $mail->setTo(array(sfPlop::get('sf_plop_messaging_to_email') => sfPlop::get('sf_plop_messaging_to_name')));
            }
        } else {
            $mail->setTo(array(sfPlop::get('sf_plop_messaging_to_email') => sfPlop::get('sf_plop_messaging_to_name')));
        }
        if ($this->getOption('subject')) {
            $mail->setSubject($this->getOption('subject'));
        } else {
            $mail->setSubject(sfPlop::get('sf_plop_messaging_subject'));
        }
        $this->mail = $mail;
    }
コード例 #24
0
 public function testTransportSendMultipart()
 {
     $container = $this->createContainer();
     /** @var MandrillTransport $transport */
     $transport = $container->get('swiftmailer.mailer.transport.accord_mandrill');
     $message = new \Swift_Message('TEST SUBJECT', '<p>test html body<p>', 'text/html');
     $message->setTo('*****@*****.**');
     $message->setFrom('*****@*****.**');
     $message->addPart('test text body', 'text/plain');
     $result = $transport->send($message);
     $this->assertEquals(1, $result, 'One multipart message should have been sent to Mandrill');
 }
コード例 #25
0
ファイル: DefaultMailBuilder.php プロジェクト: amin1984/Behat
 /**
  * (non-PHPdoc)
  * @see AppCommon\CommonMailBundle.MailBuilder::buildMessage()
  */
 public function buildMessage($body, $subject, $recipient = null)
 {
     $message = new \Swift_Message();
     $message->setFrom($this->container->getParameter('mailer_sender'), $this->container->getParameter('mailer_sender_name'));
     $message->setSubject($subject);
     $message->setBody($body);
     $message->setContentType('text/html');
     if (null !== $recipient) {
         $message->setTo($recipient);
     }
     return $message;
 }
コード例 #26
0
 function send_breakin_alert($email, $password)
 {
     $transporter = new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl');
     $transporter->setUsername('');
     $transporter->setPassword('');
     $message = new Swift_Message($transporter);
     $message->setTo(array($email => $email));
     $message->setSubject("Note to Myself - Break-in Attempt");
     $message->addPart("Your password has been reset after 3 failed log-in attempts.</br>Your new password is <strong>{$password}</strong>", 'text/html');
     $message->setFrom("", "");
     $mailer = new Swift_Mailer($transporter);
     $mailer->send($message);
 }
コード例 #27
0
 /**
  * Send message to recipient
  *
  * @param array $recipient ['*****@*****.**' => 'TestName']
  * @param string $subject
  * @param string $message
  * @param array $placeholders mail body variables
  * @return int count of successfully
  */
 public function send(array $recipient, $subject, $message, array $placeholders = [])
 {
     // create message if not exists
     $this->createMessage($subject, $message, $placeholders);
     // add recipient
     $this->message->setTo($recipient['email']);
     try {
         // send message
         return $this->mailer->send($this->message);
     } catch (\Exception $e) {
         throw new MailException($e->getMessage());
     }
 }
コード例 #28
0
ファイル: SwiftMailer.php プロジェクト: msalsas/misc-bundle
 protected function send($content, array $records)
 {
     $record = $this->getWorstRecord($records);
     $subject = $record['message'];
     // Don't wrap (Gmail sets white-space to pre-wrap)
     $body = '<pre style="white-space: pre !important">' . htmlspecialchars($content) . '</pre>';
     $message = new \Swift_Message();
     $message->setFrom($this->from);
     $message->setTo($this->to);
     $message->setSubject($subject);
     $message->setBody($body, 'text/html');
     $this->mailer->send($message);
 }
コード例 #29
0
ファイル: MailBll.php プロジェクト: emilymwang8/ajk-broker
 /**
  * 邮件发送
  * @param recipient 邮件接收方email
  * @param mailsubject 邮件主题
  * @param mailbody 邮件内容
  * @return boolean
  */
 private function send_mail($recipient, $mailsubject, $mailbody)
 {
     try {
         $message = new Swift_Message($mailsubject);
         $message->setFrom("安居客<" . $this->sender . ">");
         $message->setTo($recipient);
         $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8"));
         $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8"));
         Mail_Queue::put($this->sender, $recipient, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
コード例 #30
-1
 public function testCreatesPreviewFiles()
 {
     $message = new Swift_Message('Foo subject', '<html>Body</html>', 'text/html');
     $message->setFrom('*****@*****.**', 'Jack Black');
     $message->setTo('*****@*****.**');
     $files = m::mock('Illuminate\\Filesystem\\Filesystem');
     $transport = new PreviewTransport($files, 'framework/emails');
     $files->shouldReceive('exists')->once()->with('framework/emails')->andReturn(true);
     $files->shouldReceive('files')->once()->with('framework/emails')->andReturn([]);
     $files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.html', m::any());
     $files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.eml', $message->toString());
     $transport->send($message);
 }