本文整理汇总了PHP中Zend\Mime\Message::getParts方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::getParts方法的具体用法?PHP Message::getParts怎么用?PHP Message::getParts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Mime\Message
的用法示例。
在下文中一共展示了Message::getParts方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetGetParts
public function testSetGetParts()
{
$msg = new Mime\Message();
// No Parts
$p = $msg->getParts();
$this->assertTrue(is_array($p));
$this->assertTrue(count($p) == 0);
$p2 = array();
$p2[] = new Mime\Part('This is a test');
$p2[] = new Mime\Part('This is another test');
$msg->setParts($p2);
$p = $msg->getParts();
$this->assertTrue(is_array($p));
$this->assertTrue(count($p) == 2);
}
示例2: assertMimeMessages
/**
* Assert mime messages
*
* @param array $expected
* @param \Zend\Mime\Message $actual
*/
public static function assertMimeMessages($expected, Mime\Message $actual)
{
$found = array();
foreach ($actual->getParts() as $part) {
/* @var $part \Zend\Mime\Part */
static::assertInstanceOf('Zend\\Mime\\Part', $part);
$contentType = strtolower($part->type);
if (empty($contentType)) {
foreach ($part->getHeadersArray() as $header) {
list($field, $value) = $header;
if (strtolower($field) === 'content-type') {
$contentType = strtolower(preg_replace('/^\\s*([^;]+).*$/', '$1', $value));
break;
}
}
}
foreach ($expected as $mimeType => $rawContent) {
if (strtolower($mimeType) == $contentType) {
static::assertEquals($rawContent, $part->getRawContent(), sprintf('Content do not match in mime-type "%s"', $mimeType));
$found[$mimeType] = true;
}
}
}
foreach ($expected as $mimeType => $rawContent) {
static::assertFalse(empty($found[$mimeType]), sprintf('Content not found in mime-type "%s"', $mimeType));
}
}
示例3: 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);
}
//.........这里部分代码省略.........
示例4: 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);
}
示例5: getAttachments
/**
* @param Message $mimeMessage
* @return array
*/
protected function getAttachments(Message $mimeMessage)
{
$attachments = [];
$parts = $mimeMessage->getParts();
/** @var \Zend\Mime\Part $part */
foreach ($parts as $part) {
if (!isset($part->filename)) {
continue;
}
$attachments[] = ['content' => $part->getContent(), 'type' => $part->type, 'name' => $part->filename];
}
return $attachments;
}
示例6: sendMixedMessage
/**
* Sends a mixed message via email
* @param string[] $message
* @param string[] $templates
* @param string[] $variables
* @return $this
*/
public function sendMixedMessage(array $message, array $templates, array $variables = [])
{
//create the message
$mailMessage = $this->createMessage($message);
//render the templates
$contentMimeMessage = new MimeMessage();
foreach ($templates as $mimeType => $template) {
//render the template
$viewContent = $this->renderTemplate($template, $variables);
//add the template to the message
$mimePart = new MimePart($viewContent);
$mimePart->type = $mimeType;
$contentMimeMessage->addPart($mimePart);
}
//combine the alternative content into a single mime part
if ($contentMimeMessage->isMultiPart()) {
$contentMimePart = new MimePart($contentMimeMessage->generateMessage());
$contentMimePart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $contentMimeMessage->getMime()->boundary() . '"';
$contentMimeParts = [$contentMimePart];
} else {
$contentMimeParts = $contentMimeMessage->getParts();
}
//order the content before any attachments
$finalMimeMessage = new MimeMessage();
$finalMimeMessage->setParts(array_merge($contentMimeParts, $mailMessage->getBody()->getParts()));
$mailMessage->setBody($finalMimeMessage);
//let the client choose which part to display
if ($mailMessage->getBody()->isMultiPart()) {
$mailMessage->getHeaders()->get('content-type')->setType('multipart/mixed');
}
//send the message
return $this->sendMessage($mailMessage);
}