当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::generateMessage方法代码示例

本文整理汇总了PHP中Zend\Mime\Message::generateMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::generateMessage方法的具体用法?PHP Message::generateMessage怎么用?PHP Message::generateMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mime\Message的用法示例。


在下文中一共展示了Message::generateMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendMail

 /**
  * sendMail
  * @param string $subject
  * @param array $aMail
  */
 public function sendMail($subject = '', $aMail = array())
 {
     $message = new Message();
     $message->setEncoding("UTF-8");
     $message->setFrom($this->aMailConf['mailFromMail'], $this->aMailConf['mailFromName']);
     foreach ($aMail as $mail) {
         //destinatários
         $message->addTo($mail);
     }
     //assunto
     $message->setSubject($subject);
     //cria o corpo da mensagem
     $body = new MimeMessage();
     $contentPart = new MimePart($this->content->generateMessage());
     $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $this->content->getMime()->boundary() . '"';
     $messageType = 'multipart/related';
     //adiciona o html e o txt
     $body->addPart($contentPart);
     foreach ($this->aAttachments as $attachment) {
         $body->addPart($attachment);
     }
     //monta o corpo
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType($messageType);
     //enviar
     try {
         $this->transport->send($message);
     } catch (\Zend\Mail\Protocol\Exception\RuntimeException $e) {
         return $e;
     }
     return true;
 }
开发者ID:nfephp-org,项目名称:sped-common,代码行数:37,代码来源:BaseMail.php

示例2: sendHTML

 public function sendHTML($to, $from, $subject, $html, $attachments = false, $headers = false, $plain = false, $inlineImages = false)
 {
     if ($inlineImages) {
         user_error('The SES mailer does not support inlining images', E_USER_NOTICE);
     }
     $htmlPart = new Mime\Part($html);
     $htmlPart->type = Mime\Mime::TYPE_HTML;
     $htmlPart->charset = 'utf-8';
     $htmlPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
     $plainPart = new Mime\Part($plain ?: \Convert::xml2raw($html));
     $plainPart->type = Mime\Mime::TYPE_TEXT;
     $plainPart->charset = 'utf-8';
     $plainPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
     $alternatives = new Mime\Message();
     $alternatives->setParts(array($plainPart, $htmlPart));
     $alternativesPart = new Mime\Part($alternatives->generateMessage());
     $alternativesPart->type = Mime\Mime::MULTIPART_ALTERNATIVE;
     $alternativesPart->boundary = $alternatives->getMime()->boundary();
     $body = new Mime\Message();
     $body->addPart($alternativesPart);
     if ($attachments) {
         $this->addAttachments($body, $attachments);
     }
     $this->sendMessage($to, $from, $subject, $body, $headers);
 }
开发者ID:owindsor,项目名称:silverstripe-ses,代码行数:25,代码来源:SESMailer.php

示例3: createMultiPartBody

 /**
  * Creates a multi-part message body with plain text and HTML (from Markdown)
  *
  * @param string $text
  * @return \Zend\Mime\Message
  */
 public function createMultiPartBody($text)
 {
     $plain = new MimePart($text);
     $plain->type = "text/plain";
     $markdown = new Markdown();
     $html = new MimePart($markdown->transform($text));
     $html->type = "text/html";
     $alternatives = new MimeMessage();
     $alternatives->setParts(array($plain, $html));
     $alternatives->type = "multipart/alternative";
     $part = new MimePart($alternatives->generateMessage());
     $part->type = "multipart/alternative;\n boundary=\"" . $alternatives->getMime()->boundary() . "\"";
     $body = new MimeMessage();
     $body->addPart($part);
     return $body;
 }
开发者ID:outeredge,项目名称:edge-zf2,代码行数:22,代码来源:Message.php

示例4: setBody

 /**
  * Set body with optional attachments
  * 
  * @param \Zend\Mime\Message|strin $body
  * @param array $attachments
  * @return type
  */
 public function setBody($body, $html = null, array $attachments = [])
 {
     if (!is_object($body) && (is_string($html) || $attachments)) {
         $parts = [];
         if (!is_null($body)) {
             $text = new Mime\Part($body);
             $text->type = Mime\Mime::TYPE_TEXT;
             $text->charset = $this->encoding ?: 'utf-8';
             $text->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
             $parts[] = $text;
         }
         if (!is_null($html)) {
             $html = new Mime\Part($html);
             $html->type = Mime\Mime::TYPE_HTML;
             $html->charset = $this->encoding ?: 'utf-8';
             $html->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
             $parts[] = $html;
             $type = 'multipart/alternative';
             if ($attachments) {
                 $content = new Mime\Message();
                 $content->setParts($parts);
                 $part = new Mime\Part($content->generateMessage());
                 $part->type = "multipart/alternative;\n boundary=\"" . $content->getMime()->boundary() . '"';
                 $parts = [$part];
                 $type = 'multipart/related';
             }
         }
         foreach ($attachments as $path) {
             $resource = fopen($path, 'r');
             $attachment = new Mime\Part($resource);
             $attachment->type = mime_content_type($path);
             $attachment->filename = basename($path);
             $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
             $attachment->encoding = Mime\Mime::ENCODING_BASE64;
             $parts[] = $attachment;
         }
         $body = new Mime\Message();
         $body->setParts($parts);
     }
     parent::setBody($body);
     if (isset($type)) {
         $this->getHeaders()->get('content-type')->setType($type);
     }
     return $this;
 }
开发者ID:phower,项目名称:zf2-mail-module,代码行数:52,代码来源:Message.php

示例5: testGenerate

 public function testGenerate()
 {
     $msg = new Mime\Message();  // No Parts
     $p1 = new Mime\Part('This is a test');
     $p2 = new Mime\Part('This is another test');
     $msg->addPart($p1);
     $msg->addPart($p2);
     $res = $msg->generateMessage();
     $mime = $msg->getMime();
     $boundary = $mime->boundary();
     $p1 = strpos($res, $boundary);
     // $boundary must appear once for every mime part
     $this->assertTrue($p1 !== false);
     if ($p1) {
         $p2 = strpos($res, $boundary, $p1 + strlen($boundary));
         $this->assertTrue($p2 !== false);
     }
     // check if the two test messages appear:
     $this->assertTrue(strpos($res, 'This is a test') !== false);
     $this->assertTrue(strpos($res, 'This is another test') !== false);
     // ... more in ZMailTest
 }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:22,代码来源:MessageTest.php

示例6: sendEmail

 function sendEmail($to, $subject, $html, $text, $attachments = null)
 {
     // HTML part
     $htmlPart = new Mime\Part($html);
     $htmlPart->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE);
     $htmlPart->setType(Mime\Mime::TYPE_HTML);
     // Plain text part
     $textPart = new Mime\Part($text);
     $textPart->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE);
     $textPart->setType(Mime\Mime::TYPE_TEXT);
     $body = new Mime\Message();
     if ($attachments) {
         // With attachments, we need a multipart/related email. First part
         // is itself a multipart/alternative message
         $content = new Mime\Message();
         $content->addPart($textPart);
         $content->addPart($htmlPart);
         $contentPart = new Mime\Part($content->generateMessage());
         $contentPart->setType(Mime\Mime::MULTIPART_ALTERNATIVE);
         $contentPart->setBoundary($content->getMime()->boundary());
         $body->addPart($contentPart);
         $messageType = Mime\Mime::MULTIPART_RELATED;
         // Add each attachment
         foreach ($attachments as $thisAttachment) {
             $attachment = new Mime\Part($thisAttachment['content']);
             $attachment->filename = $thisAttachment['filename'];
             $attachment->type = Mime\Mime::TYPE_OCTETSTREAM;
             $attachment->encoding = Mime\Mime::ENCODING_BASE64;
             $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
             $body->addPart($attachment);
         }
     } else {
         // No attachments, just add the two textual parts to the body
         $body->setParts([$textPart, $htmlPart]);
         $messageType = Mime\Mime::MULTIPART_ALTERNATIVE;
     }
     // attach the body to the message and set the content-type
     $message = new Message();
     $message->addTo($to);
     $message->setEncoding($this->encoding);
     $message->addFrom($this->fromEmail, $this->fromName);
     $message->setSubject($subject);
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType($messageType);
     $this->getTransport()->send($message);
 }
开发者ID:zetta-code,项目名称:tss-bootstrap,代码行数:46,代码来源:EmailPlugin.php

示例7: sendEmail

 public function sendEmail($template = 'message', $emailOptions = array())
 {
     $emailOptions = array_merge($this->config, $emailOptions);
     $content = $this->renderEmail($template, $emailOptions);
     if ($emailOptions['debug']) {
         $displays = array();
         foreach ($emailOptions as $key => $value) {
             if ($key !== 'message' && $key != 'attachments') {
                 if (!is_object($value)) {
                     $displays[] = $key . ': <strong>' . (is_array($value) ? implode(',', $value) : $value) . '</strong>';
                 } else {
                     $displays[] = $key . ': <strong>OBJ</strong>';
                 }
             }
         }
         echo '<div style="
                     background-color: #444; 
                     padding: 50px;
                     box-shadow: 1px 1px 10px rgba(0,0,0,0.8) inset;
             ">
                 <div style="
                             width:80%; 
                             margin:10px auto; 
                             background-color:#ffffff; 
                             box-shadow:1px 2px 5px rgba(0,0,0,0.5);
                             padding: 15px;
                 " >
                     ' . implode(' ; ', $displays) . '
                 </div>
                 <div style="
                             width:80%; 
                             margin:10px auto; 
                             background-color:#ffffff; 
                             box-shadow:1px 2px 5px rgba(0,0,0,0.5);
                 " >' . $content . '</div>' . (isset($emailOptions['attachments']) && $emailOptions['attachments'] ? '<div style="
                             width:80%; 
                             margin:10px auto; 
                             background-color:#ffffff; 
                             box-shadow:1px 2px 5px rgba(0,0,0,0.5);
                             padding: 15px;
                 " >Mit Anhang</div>' : '') . '</div>';
     }
     $attachments = isset($emailOptions['attachments']) && $emailOptions['attachments'] && is_array($emailOptions['attachments']) ? $emailOptions['attachments'] : array();
     $message = new Message();
     $message->addTo($emailOptions['to']);
     $message->addFrom($emailOptions['from']);
     $message->setSubject($emailOptions['subject']);
     if ($emailOptions['bcc']) {
         $message->addBcc($emailOptions['bcc']);
     }
     if ($emailOptions['cc']) {
         $message->addCc($emailOptions['cc']);
     }
     if ($this->html) {
         // HTML part
         $htmlPart = new MimePart($content);
         $htmlPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
         $htmlPart->type = "text/html; charset=UTF-8";
     }
     // Plain text part
     $textPart = new MimePart(strip_tags($content));
     $textPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $textPart->type = "text/plain; charset=UTF-8";
     $body = new MimeMessage();
     if ($attachments) {
         // With attachments, we need a multipart/related email. First part
         // is itself a multipart/alternative message
         $content = new MimeMessage();
         $content->addPart($textPart);
         if ($this->html) {
             $content->addPart($htmlPart);
         }
         $contentPart = new MimePart($content->generateMessage());
         $contentPart->type = "multipart/alternative;\n boundary=\"" . $content->getMime()->boundary() . '"';
         $body->addPart($contentPart);
         $messageType = 'multipart/related';
         // Add each attachment
         foreach ($attachments as $thisAttachment) {
             $attachment = new MimePart($thisAttachment['buffer']);
             $attachment->filename = $thisAttachment['filename'];
             $attachment->type = Mime::TYPE_OCTETSTREAM;
             $attachment->encoding = Mime::ENCODING_BASE64;
             $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
             $body->addPart($attachment);
         }
     } else {
         // No attachments, just add the two textual parts to the body
         if ($this->html) {
             $body->setParts(array($textPart, $htmlPart));
             $messageType = 'multipart/alternative';
         } else {
             $body->setParts(array($textPart));
             $messageType = 'text/plain';
         }
     }
     // attach the body to the message and set the content-type
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType($messageType);
     $message->setEncoding('UTF-8');
     if ($emailOptions['send']) {
//.........这里部分代码省略.........
开发者ID:CasasoftCH,项目名称:casamodules,代码行数:101,代码来源:EmailService.php

示例8: sendMail

 /**
  * Sends the email.
  *
  * @param bool $resetData Whether or not to reset the service to its default values.
  *
  * @throws \Exception
  *
  * @return bool
  */
 public function sendMail($resetData = true)
 {
     $_from[] = $this->from;
     $fromStr = $this->generateEmailStrings($_from);
     $toStr = $this->generateEmailStrings($this->to);
     $replyStr = $this->generateEmailStrings($this->replyto);
     $zendMailData = self::getMailerObject();
     $mail = $zendMailData['mail'];
     $transport = $zendMailData['transport'];
     if (is_array($this->from) && count($this->from)) {
         if ($this->from[0] != '') {
             $from = $this->from;
         }
     }
     if (!isset($from)) {
         $from = array(Config::get('concrete.email.default.address'), Config::get('concrete.email.default.name'));
         $fromStr = Config::get('concrete.email.default.address');
     }
     // The currently included Zend library has a bug in setReplyTo that
     // adds the Reply-To address as a recipient of the email. We must
     // set the Reply-To before any header with addresses and then clear
     // all recipients so that a copy is not sent to the Reply-To address.
     if (is_array($this->replyto)) {
         foreach ($this->replyto as $reply) {
             $mail->setReplyTo($reply[0], $reply[1]);
         }
     }
     $mail->setFrom($from[0], $from[1]);
     $mail->setSubject($this->subject);
     foreach ($this->to as $to) {
         $mail->addTo($to[0], $to[1]);
     }
     if (is_array($this->cc) && count($this->cc)) {
         foreach ($this->cc as $cc) {
             $mail->addCc($cc[0], $cc[1]);
         }
     }
     if (is_array($this->bcc) && count($this->bcc)) {
         foreach ($this->bcc as $bcc) {
             $mail->addBcc($bcc[0], $bcc[1]);
         }
     }
     $headers = $mail->getHeaders();
     if ($headers->has('messageid')) {
         $messageIdHeader = $headers->get('messageid');
     } else {
         $messageIdHeader = new \Zend\Mail\Header\MessageId();
         $headers->addHeader($messageIdHeader);
     }
     $headers->addHeaders($this->headers);
     $messageIdHeader->setId();
     $body = new MimeMessage();
     if ($this->body !== false && $this->bodyHTML !== false) {
         $alternatives = new MimeMessage();
         $text = new MimePart($this->body);
         $text->type = 'text/plain';
         $text->charset = APP_CHARSET;
         $alternatives->addPart($text);
         $html = new MimePart($this->bodyHTML);
         $html->type = 'text/html';
         $html->charset = APP_CHARSET;
         $alternatives->addPart($html);
         $alternativesPath = new MimePart($alternatives->generateMessage());
         $alternativesPath->type = 'multipart/alternative;' . Mime::LINEEND . ' boundary="' . $alternatives->getMime()->boundary() . '"';
         $body->addPart($alternativesPath);
     } elseif ($this->body !== false) {
         $text = new MimePart($this->body);
         $text->type = 'text/plain';
         $text->charset = APP_CHARSET;
         $body->addPart($text);
     } elseif ($this->bodyHTML !== false) {
         $html = new MimePart($this->bodyHTML);
         $html->type = 'text/html';
         $html->charset = APP_CHARSET;
         $body->addPart($html);
     }
     foreach ($this->attachments as $att) {
         $body->addPart($att);
     }
     if (count($body->getParts()) === 0) {
         $text = new MimePart('');
         $text->type = 'text/plain';
         $text->charset = APP_CHARSET;
         $body->addPart($text);
     }
     $mail->setBody($body);
     $sent = false;
     try {
         if (Config::get('concrete.email.enabled')) {
             $transport->send($mail);
         }
//.........这里部分代码省略.........
开发者ID:WillemAnchor,项目名称:concrete5,代码行数:101,代码来源:Service.php

示例9: testNonMultipartMessageShouldNotRemovePartFromMessage

 public function testNonMultipartMessageShouldNotRemovePartFromMessage()
 {
     $message = new Mime\Message();
     // No Parts
     $part = new Mime\Part('This is a test');
     $message->addPart($part);
     $message->generateMessage();
     $parts = $message->getParts();
     $test = current($parts);
     $this->assertSame($part, $test);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:11,代码来源:MessageTest.php

示例10: sendMail

 /**
  * Send Mail to User
  *
  * @param integer $id rentals id
  * @param array $data input data
  * @return RentalsEntityInterface
  */
 public function sendMail($address, $subject, $content_text, $content_html, $rentals_data, $mail_settings)
 {
     $message = new Message();
     $message->addTo($address)->setEncoding("UTF-8")->addFrom($mail_settings['email_sender'])->addBcc($mail_settings['email_receiver'])->setSubject($subject);
     // Set UTF-8 charset
     $headers = $message->getHeaders();
     $headers->removeHeader('Content-Type');
     $headers->addHeaderLine('Content-Type', 'text/plain; charset=UTF-8');
     $uid = "daslastenradat";
     // setting this to an existing uid updates event, a new uid adds event
     $summary = 'Lastenrad ausleihen';
     $tstart = date('Ymd\\THis', strtotime($rentals_data['from']));
     $tend = date('Ymd\\THis', strtotime($rentals_data['to']));
     $tstamp = gmdate("Ymd\\THis\\Z");
     $ical = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:PUBLISH\nBEGIN:VEVENT\nMETHOD:PUBLISH\nDTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:{$tstart}\nDTEND;TZID=Europe/Vienna;VALUE=DATE-TIME:{$tend}\nLOCATION:Verleihstation - siehe Website \nSEQUENCE:0\nUID:{$uid}\nDTSTAMP:{$tstamp}\nSUMMARY:{$summary}\nPRIORITY:5\nX-MICROSOFT-CDO-IMPORTANCE:1\nCLASS:PUBLIC\nEND:VEVENT\nEND:VCALENDAR";
     $at = new MimePart($ical);
     $at->type = 'text/calendar';
     $at->disposition = Mime::DISPOSITION_INLINE;
     $at->encoding = Mime::ENCODING_8BIT;
     $at->filename = 'termin.ics';
     //Content-Type: text/calendar; method=REQUEST
     //Content-Transfer-Encoding: Base64
     //Content-Disposition: attachment; filename=iCal-20140915-070904.ics
     //$message->addAttachment($at);
     $content = new MimeMessage();
     $htmlPart = new MimePart($content_html);
     $htmlPart->type = 'text/html';
     $textPart = new MimePart($content_text);
     $textPart->type = 'text/plain';
     $content->setParts(array($textPart, $htmlPart));
     $contentPart = new MimePart($content->generateMessage());
     $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $content->getMime()->boundary() . '"';
     $attachment = new MimePart(fopen('C:\\projekte\\lastenrad\\public\\downloads\\nutzungsbedingungen_freies_lastenrad.pdf', 'r'));
     $attachment->type = 'application/pdf';
     $attachment->encoding = Mime::ENCODING_BASE64;
     $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
     $body = new MimeMessage();
     $body->setParts(array($contentPart, $attachment, $at));
     $message->setBody($body);
     //$transport->setOptions($options);
     $this->transport->send($message);
     return true;
 }
开发者ID:andreaszobl,项目名称:software,代码行数:50,代码来源:RentalsService.php

示例11: send

 public function send()
 {
     # differ the following scenarios:
     # - plain text email
     # - plain text email with 1 or n attachments
     # - html email with text alternative
     # - html email with text alternative and 1 or n attachments
     $content = new Mime\Message();
     if (!$this->isHtmlMessage()) {
         $content->addPart($this->getTextMessage());
     } else {
         $content->addPart($this->getTextMessage());
         $content->addPart($this->getHtmlMessage());
     }
     if (count($this->getAttachments()) == 0) {
         $body = $content;
     } else {
         $contentPart = new Mime\Part($content->generateMessage());
         $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $content->getMime()->boundary() . '"';
         $body = new Mime\Message();
         $body->addPart($contentPart);
         foreach ($this->getAttachments() as $att) {
             $body->addPart($att);
         }
     }
     $message = new Mail\Message();
     $message->setEncoding('utf-8');
     $message->setBody($body);
     if ($this->isHtmlMessage()) {
         if (count($this->getAttachments()) == 0) {
             $message->getHeaders()->get('content-type')->addParameter('charset', 'utf-8')->setType('multipart/alternative');
         } else {
             $message->getHeaders()->get('content-type')->addParameter('charset', 'utf-8')->setType('multipart/mixed');
             // Important to get all attachments into this email.
         }
     } else {
         $message->getHeaders()->get('content-type')->addParameter('charset', 'utf-8')->setType('text/plain');
     }
     foreach ($this->getTo() as $user) {
         $message->addTo($user->getEmail());
     }
     foreach ($this->getCc() as $user) {
         $message->addCc($user->getEmail());
     }
     foreach ($this->getBcc() as $user) {
         $message->addBcc($user->getEmail());
     }
     $message->addFrom($this->getFrom());
     $message->setSubject($this->getSubject());
     $transport = new Mail\Transport\Sendmail();
     $transport->send($message);
 }
开发者ID:odegroot,项目名称:ers,代码行数:52,代码来源:EmailService.php

示例12: sendorderAction

 public function sendorderAction()
 {
     $pdfView = new ViewModel();
     $pdfView->setTerminal(true)->setTemplate('Application/calculator/sendorder.phtml')->setVariables(array('fetchResult' => '789'));
     $html = $this->getServiceLocator()->get('viewpdfrenderer')->getHtmlRenderer()->render($pdfView);
     $eng = $this->getServiceLocator()->get('viewpdfrenderer')->getEngine();
     $eng->load_html($html);
     $eng->render();
     $pdfCode = $eng->output();
     //file_put_contents($_SERVER['DOCUMENT_ROOT'].'/data/pdf/ac.pdf',$pdfCode);
     $content = new MimeMessage();
     $htmlPart = new MimePart("<html><body><p>Sorry,</p><p>I'm going to be late today!Короче, опоздаю..</p></body></html>");
     $htmlPart->type = 'text/html';
     $textPart = new MimePart("Sorry, I'm going to be late today!");
     $textPart->type = 'text/plain';
     $content->setParts(array($textPart, $htmlPart));
     $contentPart = new MimePart($content->generateMessage());
     $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $content->getMime()->boundary() . '"';
     //$attachment = new MimePart(fopen($_SERVER['DOCUMENT_ROOT'].'/data/pdf/ac.pdf', 'r'));
     $attachment = new MimePart($pdfCode);
     $attachment->type = 'application/pdf';
     $attachment->encoding = Mime::ENCODING_BASE64;
     $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
     $body = new MimeMessage();
     $body->setParts(array($contentPart, $attachment));
     $message = new Message();
     $message->setEncoding('utf-8')->addTo('vikitina@gmail.com')->addFrom('vikitina@gmail.com')->setSubject('will be late')->setBody($body);
     $transportConfig = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => 'vikitina@gmail.com', 'password' => 'vikabibika0987654321'), 'port' => 587));
     $transport = new SmtpTransport();
     $options = new SmtpOptions($transportConfig);
     $transport->setOptions($options);
     $transport->send($message);
     //$this->redirect()->toRoute('zfcadmin/admin_manufacturers');
 }
开发者ID:vikitina,项目名称:ekalan,代码行数:34,代码来源:CalculatorController.php

示例13: send


//.........这里部分代码省略.........
     }
     if (!empty($attachmentCollection)) {
         foreach ($attachmentCollection as $a) {
             $fileName = 'data/upload/' . $a->id;
             $attachment = new MimePart(file_get_contents($fileName));
             $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
             $attachment->encoding = Mime::ENCODING_BASE64;
             $attachment->filename = $a->get('name');
             if ($a->get('type')) {
                 $attachment->type = $a->get('type');
             }
             $attachmentPartList[] = $attachment;
         }
     }
     if (!empty($attachmentInlineCollection)) {
         foreach ($attachmentInlineCollection as $a) {
             $fileName = 'data/upload/' . $a->id;
             $attachment = new MimePart(file_get_contents($fileName));
             $attachment->disposition = Mime::DISPOSITION_INLINE;
             $attachment->encoding = Mime::ENCODING_BASE64;
             $attachment->id = $a->id;
             if ($a->get('type')) {
                 $attachment->type = $a->get('type');
             }
             $attachmentPartList[] = $attachment;
         }
     }
     $message->setSubject($email->get('name'));
     $body = new MimeMessage();
     $textPart = new MimePart($email->getBodyPlainForSending());
     $textPart->type = 'text/plain';
     $textPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $textPart->charset = 'utf-8';
     if ($email->get('isHtml')) {
         $htmlPart = new MimePart($email->getBodyForSending());
         $htmlPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
         $htmlPart->type = 'text/html';
         $htmlPart->charset = 'utf-8';
     }
     if (!empty($attachmentPartList)) {
         $messageType = 'multipart/related';
         if ($email->get('isHtml')) {
             $content = new MimeMessage();
             $content->addPart($textPart);
             $content->addPart($htmlPart);
             $messageType = 'multipart/mixed';
             $contentPart = new MimePart($content->generateMessage());
             $contentPart->type = "multipart/alternative;\n boundary=\"" . $content->getMime()->boundary() . '"';
             $body->addPart($contentPart);
         } else {
             $body->addPart($textPart);
         }
         foreach ($attachmentPartList as $attachmentPart) {
             $body->addPart($attachmentPart);
         }
     } else {
         if ($email->get('isHtml')) {
             $body->setParts(array($textPart, $htmlPart));
             $messageType = 'multipart/alternative';
         } else {
             $body = $email->getBodyPlainForSending();
             $messageType = 'text/plain';
         }
     }
     $message->setBody($body);
     if ($messageType == 'text/plain') {
         if ($message->getHeaders()->has('content-type')) {
             $message->getHeaders()->removeHeader('content-type');
         }
         $message->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=UTF-8');
     } else {
         if (!$message->getHeaders()->has('content-type')) {
             $contentTypeHeader = new \Zend\Mail\Header\ContentType();
             $message->getHeaders()->addHeader($contentTypeHeader);
         }
         $message->getHeaders()->get('content-type')->setType($messageType);
     }
     $message->setEncoding('UTF-8');
     try {
         $rand = mt_rand(1000, 9999);
         if ($email->get('parentType') && $email->get('parentId')) {
             $messageId = '' . $email->get('parentType') . '/' . $email->get('parentId') . '/' . time() . '/' . $rand . '@espo';
         } else {
             $messageId = '' . md5($email->get('name')) . '/' . time() . '/' . $rand . '@espo';
         }
         if ($email->get('isSystem')) {
             $messageId .= '-system';
         }
         $messageIdHeader = new \Zend\Mail\Header\MessageId();
         $messageIdHeader->setId($messageId);
         $message->getHeaders()->addHeader($messageIdHeader);
         $this->transport->send($message);
         $email->set('messageId', '<' . $messageId . '>');
         $email->set('status', 'Sent');
         $email->set('dateSent', date("Y-m-d H:i:s"));
     } catch (\Exception $e) {
         throw new Error($e->getMessage(), 500);
     }
     $this->useGlobal();
 }
开发者ID:chinazan,项目名称:zzcrm,代码行数:101,代码来源:Sender.php

示例14: mailtestAction

 public function mailtestAction()
 {
     $emailService = new Service\EmailFactory();
     $emailService->setFrom('prereg@eja.net');
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $user = $em->getRepository("ErsBase\\Entity\\User")->findOneBy(array('email' => 'andi@sixhop.net'));
     $user = new Entity\User();
     $user->setEmail('andi@inbaz.org');
     $emailService->addTo($user);
     $emailService->setSubject('Testmail');
     $emailService->setHtmlMessage('<h1>Testmail</h1>');
     #$emailService->setTextMessage('Testmail');
     $emailService->addAttachment(getcwd() . '/public/img/EJC2015_Terms_and_Services.pdf');
     $emailService->addAttachment(getcwd() . '/public/img/logo.jpg');
     $emailService->addAttachment(getcwd() . '/public/img/ejc_logo.png');
     $emailService->send();
     return true;
     $content = new Mime\Message();
     $textContent = 'This is the text of the email.';
     $textPart = new Mime\Part($textContent);
     $textPart->type = 'text/plain';
     $htmlMarkup = '<html><body><h1>This is the text of the email.</h1></body></html>';
     $htmlPart = new Mime\Part($htmlMarkup);
     $htmlPart->type = 'text/html';
     $content->setParts(array($textPart, $htmlPart));
     $contentPart = new Mime\Part($content->generateMessage());
     $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $content->getMime()->boundary() . '"';
     $pathToImage = getcwd() . '/public/img/logo.jpg';
     $attachment = new Mime\Part(fopen($pathToImage, 'r'));
     #$attachment->type = 'application/pdf';
     $attachment->type = 'image/jpeg';
     $attachment->filename = 'logo.jpg';
     $attachment->encoding = Mime\Mime::ENCODING_BASE64;
     $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
     $body = new Mime\Message();
     $body->setParts(array($contentPart, $attachment));
     $message = new Message();
     $message->setEncoding('utf-8');
     $message->addTo('andi@inbaz.org');
     $message->addFrom('prereg@eja.net');
     $message->setSubject('Testmail');
     $message->setBody($body);
     $transport = new Transport\Sendmail();
     $transport->send($message);
 }
开发者ID:odegroot,项目名称:ers,代码行数:45,代码来源:TestController.php

示例15: getMessageBody

 /**
  * @param $body
  * @param null $mimeType
  * @return array
  */
 public function getMessageBody($body, $mimeType = null)
 {
     // Make sure we have a string.
     if ($body instanceof ViewModel) {
         $body = $this->getView()->render($body);
         $detectedMimeType = Mime::TYPE_HTML;
     } elseif (null === $body) {
         $detectedMimeType = Mime::TYPE_TEXT;
         $body = '';
     }
     if (null !== ($layout = $this->getLayout())) {
         $layout->setVariables(array('content' => $body));
         $detectedMimeType = Mime::TYPE_HTML;
         $body = $this->parseTemplate($layout);
     }
     if (null === $mimeType && !isset($detectedMimeType)) {
         $mimeType = preg_match("/<[^<]+>/", $body) ? Mime::TYPE_HTML : Mime::TYPE_TEXT;
     } elseif (null === $mimeType) {
         $mimeType = $detectedMimeType;
     }
     $htmlPart = new MimePart($body);
     $htmlPart->type = $mimeType;
     $htmlPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     if (null !== ($charset = $this->getOption('charset'))) {
         $htmlPart->charset = $charset;
     }
     if ($mimeType === Mime::TYPE_HTML) {
         $text = $this->renderTextBody($body);
         $textPart = new MimePart($text);
         $textPart->type = Mime::TYPE_TEXT;
         $textPart->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
         if ($this->getOption('charset')) {
             $textPart->charset = $this->getOption('charset');
         }
     }
     $bodyMessage = new MimeMessage();
     if (count($this->attachments) > 0) {
         $content = new MimeMessage();
         if (isset($textPart)) {
             $content->addPart($textPart);
         }
         if (isset($content)) {
             $content->addPart($htmlPart);
         }
         $contentPart = new MimePart($content->generateMessage());
         $contentPart->type = 'multipart/alternative; boundary="' . $content->getMime()->boundary() . '"';
         $bodyMessage->addPart($contentPart);
         $messageType = Mime::MULTIPART_RELATED;
         foreach ($this->attachments as $attachment) {
             $bodyMessage->addPart($attachment);
         }
     } else {
         if (isset($textPart)) {
             $bodyMessage->addPart($textPart);
         }
         if (isset($htmlPart)) {
             $bodyMessage->addPart($htmlPart);
         }
         $messageType = Mime::MULTIPART_ALTERNATIVE;
     }
     return ['body' => $bodyMessage, 'type' => $messageType];
 }
开发者ID:uthando-cms,项目名称:uthando-mail,代码行数:67,代码来源:Mail.php


注:本文中的Zend\Mime\Message::generateMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。