Skip to content

Instantly share code, notes, and snippets.

@jeremyquinton
Created December 1, 2013 02:03
Show Gist options
  • Save jeremyquinton/7727692 to your computer and use it in GitHub Desktop.
Save jeremyquinton/7727692 to your computer and use it in GitHub Desktop.
<?php
require "vendor/autoload.php";
use Zend\Mail as Mail;
use Zend\Mime as Mime;
$mimeMessage = new Mime\Message;
$img = new Mime\Part(fopen(__DIR__ . "/blank.png", "r"));
$img->type = "image/png";
$img->disposition = Mime\Mime::DISPOSITION_INLINE;
$img->encoding = Mime\Mime::ENCODING_BASE64;
$img->filename = "blank.png";
$img->id = "imgblank";
$mimeMessage->addPart($img);
$html = new Mime\Part("<html><head></head><body>This is a test <img src='cid:imgblank'></body></html>");
$html->type = Mime\Mime::TYPE_HTML;
$html->charset = "utf-8";
$html->encoding = Mime\Mime::ENCODING_8BIT;
$mimeMessage->addPart($html);
$message = new Mail\Message;
$message->setBody($mimeMessage)
->addFrom("[email protected]")
->addTo("[email protected]")
->setSubject("Test");
echo strlen($message->getBodyText()) . PHP_EOL;
//Body text length correct
echo strlen($message->getBodyText()) . PHP_EOL;
//Body text length incorrect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment