示例#1
2
 public function sendMessage()
 {
     $transport = \Swift_SmtpTransport::newInstance($this->mta->address, $this->mta->port);
     $swift = \Swift_Mailer::newInstance($transport);
     $message = new \Swift_Message();
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-GreenArrow-MailClass', 'SIGMA_NEWEMKTG_DEVEL');
     $message->setSubject($this->data->subject);
     $message->setFrom(array($this->data->fromEmail => $this->data->fromName));
     $message->setBody($this->html, 'text/html');
     $message->addPart($this->plainText, 'text/plain');
     $this->logger->log("Crea contenido del correo para enviar");
     foreach ($this->data->target as $to) {
         $message->setTo($to);
         $this->logger->log("Preparandose para enviar mensaje a: {$to}");
         $recipients = $swift->send($message, $failures);
         if ($recipients) {
             \Phalcon\DI::getDefault()->get('logger')->log('Recover Password Message successfully sent!');
         } else {
             throw new Exception('Error while sending message: ' . $failures);
         }
     }
 }
 /**
  * Создаём основу сообщения
  */
 private function _setMessage()
 {
     $to = $this->_args['email'];
     $from = $this->_args['from'];
     $subj = $this->_args['subject'];
     $body = $this->_args['body'];
     $this->_message->setSubject($subj)->setFrom($from)->setTo($to)->setBody($body, 'text/plain');
 }
示例#3
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);
 }
示例#4
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;
 }
示例#5
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 testSend()
 {
     $message = new Swift_Message();
     $message->setFrom('*****@*****.**', 'Johnny #5');
     $message->setSubject('Is alive!');
     $message->addTo('*****@*****.**', 'A. Friend');
     $message->addTo('*****@*****.**');
     $message->addCc('*****@*****.**');
     $message->addCc('*****@*****.**', 'Extra 2');
     $message->addBcc('*****@*****.**');
     $message->addBcc('*****@*****.**', 'Extra 4');
     $message->addPart('<q>Help me Rhonda</q>', 'text/html');
     $message->addPart('Doo-wah-ditty.', 'text/plain');
     $attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
     $attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
     $attachment2->setDisposition('inline');
     $message->attach($attachment);
     $message->attach($attachment2);
     $message->setPriority(1);
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-PM-Tag', 'movie-quotes');
     $messageId = $headers->get('Message-ID')->getId();
     $transport = new PostmarkTransportStub('TESTING_SERVER');
     $client = $this->getMock('GuzzleHttp\\Client', array('request'));
     $transport->setHttpClient($client);
     $o = PHP_OS;
     $v = phpversion();
     $client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <*****@*****.**>', 'To' => '"A. Friend" <*****@*****.**>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <*****@*****.**>', 'Bcc' => 'another+3@example.com,"Extra 4" <*****@*****.**>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]]));
     $transport->send($message);
 }
示例#7
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);
 }
示例#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);
 }
 /**
  * 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;
     }
 }
 /**
  * @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;
 }
 /**
  * Создаём основу сообщения
  */
 private function _setMessage()
 {
     if ((int) $this->_args['type'] === 0) {
         $subj = 'АМТ банк: списание средств';
         $body = "АМТ банк: Списание средств: {$this->_args['amount']};";
     } else {
         $subj = 'АМТ банк: внесение средств';
         $body = "АМТ банк: Внесение средств: {$this->_args['amount']};";
     }
     $body .= " со счёта: {$this->_args['account']};\n";
     if (isset($this->_args['payment'])) {
         $body .= "на сумму: {$this->_args['payment']};\n";
     }
     $body .= "операция: {$this->_args['place']}; дата: " . $this->_args['timestamp'] . ";\n" . "доступный остаток: {$this->_args['balance']};";
     $this->_message->setSubject($subj)->setFrom('*****@*****.**')->setTo('*****@*****.**')->setBody($body, 'text/plain');
 }
 private function sendInvitationEmail($subject, $name, $email, $body, $expert, $mailer)
 {
     $message = new Swift_Message();
     $message->setFrom('Expert bank');
     $message->setSubject($subject);
     $message->setBody("U hebt via de expertbank een bericht ontvangen van {$name} ({$email}):\n\n{$body}");
     $mailer->send($message, $expert->getEmail(), $email);
 }
 /**
  * @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;
 }
示例#14
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;
 }
示例#15
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;
 }
示例#16
0
 public function send()
 {
     if (is_null($this->subject)) {
         $subject = $this->report->getName() . ' for ' . date('m/d/y');
     } else {
         $subject = $this->subject;
     }
     $message = new \Swift_Message();
     $message->setSubject($subject)->setFrom($this->from)->setTo($this->to)->setBody("Your report \"{$this->report->getName()}\"  has been run and is attached to this email.")->attach($this->makeAttachment());
     $this->mailer->send($message);
 }
示例#17
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;
    }
示例#19
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;
 }
示例#20
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);
 }
示例#21
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);
 }
 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);
 }
 public function testMessageSubjectFormatting()
 {
     // Wire Mailer to expect a specific Swift_Message with a customized Subject
     $messageTemplate = new \Swift_Message();
     $messageTemplate->setSubject('Alert: %level_name% %message%');
     $receivedMessage = null;
     $this->mailer->expects($this->once())->method('send')->with($this->callback(function ($value) use(&$receivedMessage) {
         $receivedMessage = $value;
         return true;
     }));
     $handler = new SwiftMailerHandler($this->mailer, $messageTemplate);
     $records = array($this->getRecord(Logger::EMERGENCY));
     $handler->handleBatch($records);
     $this->assertEquals('Alert: EMERGENCY test', $receivedMessage->getSubject());
 }
示例#24
0
 /**
  * Create message from config params
  *
  * @param       $subject
  * @param       $message
  * @param array $placeholders email message placeholders in body
  *
  */
 public function createMessage($subject, $message, array $placeholders = [])
 {
     // get mail configurations
     $config = $this->getConfig();
     // add smtp exception plugin to resolve SMTP errors
     $this->mailer->registerPlugin(new MailSMTPException());
     // add decorator plugin to resolve messages placeholders
     $this->mailer->registerPlugin(new \Swift_Plugins_DecoratorPlugin($placeholders));
     // prepare message to transport
     $this->message = \Swift_Message::newInstance();
     $this->message->setFrom([$config['fromEmail'] => $config['fromName']]);
     $this->message->setSubject($subject);
     $this->message->setBody($message, 'text/html');
     $this->message->setCharset('UTF-8');
     $this->message->setReadReceiptTo($config['fromEmail']);
     $this->message->setPriority(1);
 }
 /**
  * @Route("/contact/mail")
  * @Template("AppBundle:ContactMail:contactMail.html.twig")
  */
 public function contactMailAction(Request $request)
 {
     $form = $this->createFormBuilder()->add("from", "text")->add('subject', 'text', ['attr' => ['placeholder' => 'Title']])->add('message', 'textarea')->add('send', 'submit', ['label' => 'Submit'])->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->addFlash('notice', 'Richiesta ricevuta');
         $mailAdmin = $this->getParameter('email_amministratore');
         $data = $form->getData();
         $message = new \Swift_Message();
         $message->setTo($mailAdmin, 'Admin del sito');
         $message->setFrom($data['from']);
         $message->setSubject($data['subject']);
         $message->setBody($data['message']);
         $this->get('mailer')->send($message);
     }
     return ['form_di_contatto' => $form->createView()];
 }
 public function testMessageCanBeCustomizedGivenLoggedData()
 {
     // Wire Mailer to expect a specific Swift_Message with a customized Subject
     $expectedMessage = new \Swift_Message();
     $this->mailer->expects($this->once())->method('send')->with($this->callback(function ($value) use($expectedMessage) {
         return $value instanceof \Swift_Message && $value->getSubject() === 'Emergency' && $value === $expectedMessage;
     }));
     // Callback dynamically changes subject based on number of logged records
     $callback = function ($content, array $records) use($expectedMessage) {
         $subject = count($records) > 0 ? 'Emergency' : 'Normal';
         $expectedMessage->setSubject($subject);
         return $expectedMessage;
     };
     $handler = new SwiftMailerHandler($this->mailer, $callback);
     // Logging 1 record makes this an Emergency
     $records = array($this->getRecord(Logger::EMERGENCY));
     $handler->handleBatch($records);
 }
示例#27
0
 /**
  * @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);
 }
示例#28
0
文件: Bug38Test.php 项目: dosh93/shop
 public function testWritingMessageToByteStreamTwiceUsingAFileAttachment()
 {
     $message = new Swift_Message();
     $message->setSubject('test subject');
     $message->setTo('*****@*****.**');
     $message->setCc('*****@*****.**');
     $message->setFrom('*****@*****.**');
     $attachment = Swift_Attachment::fromPath($this->_attFile);
     $message->attach($attachment);
     $message->setBody('HTML part', 'text/html');
     $id = $message->getId();
     $date = preg_quote(date('r', $message->getDate()), '~');
     $boundary = $message->getBoundary();
     $streamA = new Swift_ByteStream_ArrayByteStream();
     $streamB = new Swift_ByteStream_ArrayByteStream();
     $pattern = '~^' . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: user@domain.tld' . "\r\n" . 'To: user@domain.tld' . "\r\n" . 'Cc: other@domain.tld' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/mixed;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: ' . $this->_attFileType . '; name=' . $this->_attFileName . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=' . $this->_attFileName . "\r\n" . "\r\n" . preg_quote(base64_encode(file_get_contents($this->_attFile)), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D';
     $message->toByteStream($streamA);
     $message->toByteStream($streamB);
     $this->assertPatternInStream($pattern, $streamA);
     $this->assertPatternInStream($pattern, $streamB);
 }
示例#29
-1
 public function testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative()
 {
     $message = new Swift_Message();
     $message->setCharset('utf-8');
     $message->setSubject('test subject');
     $message->addPart('plain part', 'text/plain');
     $image = new Swift_Image('<image data>', 'image.gif', 'image/gif');
     $cid = $message->embed($image);
     $message->setBody('<img src="' . $cid . '" />', 'text/html');
     $message->setTo(array('*****@*****.**' => 'User'));
     $message->setFrom(array('*****@*****.**' => 'Other'));
     $message->setSender(array('*****@*****.**' => 'Other'));
     $id = $message->getId();
     $date = preg_quote(date('r', $message->getDate()), '~');
     $boundary = $message->getBoundary();
     $cidVal = $image->getId();
     $this->assertRegExp('~^' . 'Sender: Other <*****@*****.**>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <*****@*****.**>' . "\r\n" . 'To: User <*****@*****.**>' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/alternative;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: multipart/related;' . "\r\n" . ' boundary="(.*?)"' . "\r\n" . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . '<img.*?/>' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: inline; filename=image.gif' . "\r\n" . 'Content-ID: <' . $cidVal . '>' . "\r\n" . "\r\n" . preg_quote(base64_encode('<image data>'), '~') . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
 }
示例#30
-2
 public function testHTMLPartAppearsLastEvenWhenAttachmentsAdded()
 {
     $message = new Swift_Message();
     $message->setCharset('utf-8');
     $message->setSubject('test subject');
     $message->addPart('plain part', 'text/plain');
     $attachment = new Swift_Attachment('<data>', 'image.gif', 'image/gif');
     $message->attach($attachment);
     $message->setBody('HTML part', 'text/html');
     $message->setTo(array('*****@*****.**' => 'User'));
     $message->setFrom(array('*****@*****.**' => 'Other'));
     $message->setSender(array('*****@*****.**' => 'Other'));
     $id = $message->getId();
     $date = preg_quote($message->getDate()->format('r'), '~');
     $boundary = $message->getBoundary();
     $this->assertRegExp('~^' . 'Sender: Other <*****@*****.**>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <*****@*****.**>' . "\r\n" . 'To: User <*****@*****.**>' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/mixed;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: multipart/alternative;' . "\r\n" . ' boundary="(.*?)"' . "\r\n" . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=image.gif' . "\r\n" . "\r\n" . preg_quote(base64_encode('<data>'), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
 }