/** * Return all mail headers as an array * * If a boundary is given, a multipart header is generated with a * Content-Type of either multipart/alternative or multipart/mixed depending * on the mail parts present in the {@link $_mail \Zend\Mail\Mail object} present. * * @param string $boundary * @return array */ protected function _getHeaders($boundary) { if (null !== $boundary) { // Build multipart mail $type = $this->_mail->getType(); if (!$type) { if ($this->_mail->hasAttachments) { $type = Mime\Mime::MULTIPART_MIXED; } elseif ($this->_mail->getBodyText() && $this->_mail->getBodyHtml()) { $type = Mime\Mime::MULTIPART_ALTERNATIVE; } else { $type = Mime\Mime::MULTIPART_MIXED; } } $this->_headers['Content-Type'] = array($type . ';' . $this->EOL . " " . 'boundary="' . $boundary . '"'); $this->boundary = $boundary; } $this->_headers['MIME-Version'] = array('1.0'); return $this->_headers; }
public function testTypeAccessor() { $mail = new Mail\Mail(); $this->assertNull($mail->getType()); $mail->setType(Mime\Mime::MULTIPART_ALTERNATIVE); $this->assertEquals(Mime\Mime::MULTIPART_ALTERNATIVE, $mail->getType()); $mail->setType(Mime\Mime::MULTIPART_RELATED); $this->assertEquals(Mime\Mime::MULTIPART_RELATED, $mail->getType()); try { $mail->setType('text/plain'); $this->fail('Invalid Mime type should throw an exception'); } catch (\Exception $e) { } }