/**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * @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);
 }
 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;
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 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;
 }
 /**
  * Add html and plain text bodies or only plain text if html is empty.
  *
  * @param \Swift_Message        $message      The swiftmailer message
  * @param MailRenderedInterface $mailRendered The rendered mail
  */
 protected function addBodies(\Swift_Message $message, MailRenderedInterface $mailRendered)
 {
     $textPlain = $mailRendered->getBody();
     $html = $mailRendered->getHtmlBody();
     if (null === $html) {
         $message->setBody($textPlain, 'text/plain');
         return;
     }
     $message->setBody($html, 'text/html');
     if (null !== $textPlain) {
         $message->addPart($textPlain, 'text/plain');
     }
 }
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
 protected function _swiftMail($to, $from, $subject, $message, $attachments = [], $html = true)
 {
     $mailer = $this->__getSwiftMailer($from);
     if (is_array($to) && isset($to['email'])) {
         if (isset($to['name'])) {
             $to = [$to['email'] => $to['name']];
         } else {
             $to = $to['email'];
         }
     }
     $mail = new \Swift_Message();
     $mail->setSubject($subject)->setFrom($from['email'], $from['name'])->setTo($to);
     if (isset($from['reply-to'])) {
         if (is_array($from['reply-to']) && isset($from['email'])) {
             $mail->setReplyTo($from['reply-to']['email'], $from['reply-to']['name']);
         } else {
             $mail->setReplyTo($from['reply-to']);
         }
     }
     $mail->setBody($message, $html ? 'text/html' : 'text/plain');
     foreach ($attachments as $attachment) {
         $mail->attach(\Swift_Attachment::fromPath($attachment));
     }
     return $mailer->send($mail);
 }
Ejemplo n.º 9
0
 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();
             }
         }
     }
 }
Ejemplo n.º 10
0
 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'));
     }
 }
Ejemplo n.º 11
0
 /**
  * @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;
     }
 }
 /**
  * Send an email to a number of recipients
  * Returns the number of successful recipients, or FALSE on failure
  * @param mixed The recipients to send to.  One of string, array, 2-dimensional array or Swift_Address
  * @param mixed The address to send from. string or Swift_Address
  * @param string The message subject
  * @param string The message body, optional
  * @return int
  */
 public function send($recipients, $from, $subject, $body = null)
 {
     $this->addTo($recipients);
     $sender = false;
     if (is_string($from)) {
         $sender = $this->stringToAddress($from);
     } elseif ($from instanceof Swift_Address) {
         $sender = $from;
     }
     if (!$sender) {
         return false;
     }
     $this->message->setSubject($subject);
     if ($body) {
         $this->message->setBody($body);
     }
     try {
         if (!$this->exactCopy && !$this->recipients->getCc() && !$this->recipients->getBcc()) {
             $sent = $this->swift->batchSend($this->message, $this->recipients, $sender);
         } else {
             $sent = $this->swift->send($this->message, $this->recipients, $sender);
         }
         if ($this->autoFlush) {
             $this->flush();
         }
         return $sent;
     } catch (Swift_ConnectionException $e) {
         $this->setError("Sending failed:<br />" . $e->getMessage());
         return false;
     }
 }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
0
 /**
  * Send an email to a number of recipients
  * Returns the number of successful recipients, or FALSE on failure
  * @param mixed The recipients to send to.  One of string, array, 2-dimensional array or Swift_Address
  * @param mixed The address to send from. string or Swift_Address
  * @param string The message subject
  * @param string The message body, optional
  * @return int
  */
 function send($recipients, $from, $subject, $body = null)
 {
     $this->addTo($recipients);
     $sender = false;
     if (is_string($from)) {
         $sender = $this->stringToAddress($from);
     } elseif (is_a($from, "Swift_Address")) {
         $sender =& $from;
     }
     if (!$sender) {
         return false;
     }
     $this->message->setSubject($subject);
     if ($body) {
         $this->message->setBody($body);
     }
     $sent = 0;
     Swift_Errors::expect($e, "Swift_ConnectionException");
     if (!$this->exactCopy && !$this->recipients->getCc() && !$this->recipients->getBcc()) {
         $sent = $this->swift->batchSend($this->message, $this->recipients, $sender);
     } else {
         $sent = $this->swift->send($this->message, $this->recipients, $sender);
     }
     if (!$e) {
         Swift_Errors::clear("Swift_ConnectionException");
         if ($this->autoFlush) {
             $this->flush();
         }
         return $sent;
     }
     $this->setError("Sending failed:<br />" . $e->getMessage());
     return false;
 }
 public function setBody($body, $contentType = null, $charset = null)
 {
     foreach ($this->vars as $key => $var) {
         $this->{$key} = $var;
     }
     $body = $this->parseContent($body);
     return parent::setBody($body, $contentType, $charset);
 }
Ejemplo n.º 17
0
 /**
  * @param \FTC\Bundle\AuthBundle\Entity\User $recipient
  * @param string $subject
  * @param string $body
  *
  * @return \Swift_Message
  */
 protected function createEmail($recipient, $subject, $body)
 {
     $email = new \Swift_Message();
     $email->addTo($recipient->getEmail(), $recipient->getFullname());
     $email->setFrom('*****@*****.**', 'FixThatCode.com');
     $email->setSubject($subject);
     $email->setBody($body, 'text/html');
     return $email;
 }
Ejemplo n.º 18
0
 public function setBody($body, $contentType = null, $charset = null)
 {
     if ($contentType === 'text/html') {
         $this->_html = (string) $body;
     } elseif ($contentType === 'text/plain') {
         $this->_text = (string) $body;
     }
     return parent::setBody($body, $contentType, $charset);
 }
Ejemplo n.º 19
0
 private function createMessage($body, $data, $config)
 {
     $message = new \Swift_Message();
     $message->setFrom($config['from']['email']);
     $message->setSubject($config['subject']);
     $message->setBody($body);
     $message->addTo($data->getEmail());
     //        $message->setSender($config['from']['name'])
     return $message;
 }
Ejemplo n.º 20
0
 /**
  * Sends an email
  * @param \Swift_Message $message An email message
  * @param string $content The message body in HTML
  * @return int The number of recipients the message was delivered to
  */
 protected static function sendEmail(\Swift_Message $message, $content)
 {
     // Lazy mailer instantiation
     if (!self::$mailer) {
         self::$mailer = \Swift_Mailer::newInstance(\Swift_SmtpTransport::newInstance(SMTP_SERVER, SMTP_SERVER_PORT));
     }
     $message->setBody($content, 'text/html', 'utf-8');
     $message->addPart(\Html2Text\Html2Text::convert(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')), 'text/plain', 'utf-8');
     return self::$mailer->send($message);
 }
Ejemplo n.º 21
0
 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;
 }
Ejemplo n.º 22
0
 /**
  * This is just for the demo sending.
  */
 public function action_send()
 {
     $message = new Swift_Message();
     $message->addTo($this->request->post('to'));
     $message->addFrom($this->request->post('from'));
     $message->setSubject($this->request->post('subject'));
     $message->setBody($this->request->post('message'));
     $mq = new MailQueue();
     $mq->add($message);
     $this->redirect('mailqueue/demo');
 }
    /**
     * 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;
    }
Ejemplo n.º 24
0
 /**
  * (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;
 }
Ejemplo n.º 25
0
function sendMail($mail, $subject, $text)
{
    $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
    $swift = \Swift_Mailer::newInstance($transport);
    $message = new \Swift_Message($subject);
    $message->setFrom(env('MAIL_FROM'));
    $message->setSender(env('MAIL_FROM'));
    $message->setReplyTo(env('MAIL_FROM'));
    $message->setBody($text, 'text/plain');
    $message->addTo($mail);
    $swift->send($message);
}
Ejemplo n.º 26
0
 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);
 }
Ejemplo n.º 27
0
 /**
  * send
  *
  * @return void
  */
 public function send()
 {
     try {
         $this->message = Swift_Message::newInstance()->setSubject($this->template->getSubject())->setCharset("utf-8");
         switch ($this->type) {
             case self::TYPE_PLAIN:
                 $this->message->setBody($this->template->getPlain(), 'text/plain');
                 break;
             case self::TYPE_HTML:
                 $html_body = $this->template->getHtml();
                 if ($this->hasEmbedImage()) {
                     $html_body = $this->embedImages($html_body);
                 }
                 $this->message->setBody($html_body, 'text/html');
                 break;
             case self::TYPE_BOTH:
             default:
                 $html_body = $this->template->getHtml();
                 if ($this->hasEmbedImage()) {
                     $html_body = $this->embedImages($html_body);
                 }
                 $this->message->setBody($html_body, 'text/html');
                 $this->message->addPart($this->template->getPlain(), 'text/plain');
                 break;
         }
         if ($this->getAttribute('reply')) {
             $this->message->setReplyTo($this->getAttribute('reply'));
         }
         $this->message->setFrom($this->getAttribute('from'))->setTo($this->getAttribute('to'));
         $this->getMailer()->send($this->message);
     } catch (Exception $exception) {
         if ($this->getTransport() && $this->getTransport()->isStarted()) {
             $this->disconnect();
         }
         throw $exception;
     }
 }
Ejemplo n.º 28
0
 /**
  * Send mail to the newly registered member
  */
 public function SendMail()
 {
     //Mail1234
     //$html = '<html> <body> <p> This is a fake email just for testing purpose </p></body>';
     $transport = Swift_SmtpTransport::newInstance('smtp.ipage.com', 465, 'ssl');
     $transport->setUsername('*****@*****.**');
     $transport->setPassword('Mail1234');
     $swift = Swift_Mailer::newInstance($transport);
     $message = new Swift_Message($this->subject);
     $message->setFrom($this->from);
     $message->setBody($this->body, 'text/html');
     $message->setTo($this->to);
     $message->addPart("testing text", 'text/plain');
     $swift->send($message, $failures);
 }
Ejemplo n.º 29
0
 public function send(\Swift_Message $message, $tplName, array $tplParams = array())
 {
     if (!$message->getFrom()) {
         $message->setFrom($this->mailerParams['from']);
     }
     if (!$message->getReturnPath()) {
         $message->setReturnPath($this->mailerParams['return_path']);
     }
     $html = $this->templating->render($tplName, $tplParams);
     $message->setBody($html, 'text/html')->addPart($this->html2text->convert($html), 'text/plain');
     if (!$message->getSubject()) {
         $message->setSubject((new Crawler($html))->filter('head title')->text());
     }
     $this->mailer->send($message);
 }
Ejemplo n.º 30
0
 public function send($html, $subject, $from, $recipient)
 {
     $transport = \Swift_SmtpTransport::newInstance($this->cfg['host'], $this->cfg['port']);
     $transport->setUsername($this->cfg['user']);
     $transport->setPassword($this->cfg['pass']);
     $swift = \Swift_Mailer::newInstance($transport);
     $message = new \Swift_Message($subject);
     $message->setFrom($from);
     $message->setBody($html, 'text/html');
     $message->setTo($recipient);
     if ($recipients = $swift->send($message, $failures)) {
         return true;
     } else {
         throw new \exception('Unable to send email');
     }
 }