oroinc/laminas-mail
oroinc/laminas-mail is a small bridge package for using Laminas Mail components within Oro applications. Provides the Laminas mail classes and configuration needed to send emails, manage transports, and integrate with Oro’s mailing features.
laminas-mail does not directly provide the ability to create and use mail
attachments. However, it allows using Laminas\Mime\Message instances, from the
laminas-mime component, for message
bodies, allowing you to create multipart emails.
The following example creates an email with two parts, HTML content and an image.
use Laminas\Mail\Message;
use Laminas\Mime\Message as MimeMessage;
use Laminas\Mime\Mime;
use Laminas\Mime\Part as MimePart;
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$image = new MimePart(fopen($pathToImage, 'r'));
$image->type = 'image/jpeg';
$image->filename = 'image-file-name.jpg';
$image->disposition = Mime::DISPOSITION_ATTACHMENT;
$image->encoding = Mime::ENCODING_BASE64;
$body = new MimeMessage();
$body->setParts([$html, $image]);
$message = new Message();
$message->setBody($body);
$contentTypeHeader = $message->getHeaders()->get('Content-Type');
$contentTypeHeader->setType('multipart/related');
Note that the above code requires us to manually specify the message content type; laminas-mime does not automatically select the multipart type for us, nor does laminas-mail populate it by default.
One of the most common email types sent by web applications is
multipart/alternative messages with both text and HTML parts.
use Laminas\Mail\Message;
use Laminas\Mime\Message as MimeMessage;
use Laminas\Mime\Mime;
use Laminas\Mime\Part as MimePart;
$text = new MimePart($textContent);
$text->type = Mime::TYPE_TEXT;
$text->charset = 'utf-8';
$text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$body = new MimeMessage();
$body->setParts([$text, $html]);
$message = new Message();
$message->setBody($body);
$contentTypeHeader = $message->getHeaders()->get('Content-Type');
$contentTypeHeader->setType('multipart/alternative');
The only differences from the first example are:
Content-Type header is now multipart/alternative.Another common task is creating multipart/alternative emails where the HTML
content refers to assets attachments (images, CSS, etc.).
To accomplish this, we need to:
Laminas\Mime\Part instance containing our multipart/alternative
message.Laminas\Mime\Message.Laminas\Mime\Part instances to the MIME message.Laminas\Mail\Message content body.multipart/related content.The following example creates a MIME message with three parts: text and HTML alternative versions of an email, and an image attachment.
use Laminas\Mail\Message;
use Laminas\Mime\Message as MimeMessage;
use Laminas\Mime\Mime;
use Laminas\Mime\Part as MimePart;
$body = new MimeMessage();
$text = new MimePart($textContent);
$text->type = Mime::TYPE_TEXT;
$text->charset = 'utf-8';
$text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$html = new MimePart($htmlMarkup);
$html->type = Mime::TYPE_HTML;
$html->charset = 'utf-8';
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$content = new MimeMessage();
// This order is important for email clients to properly display the correct version of the content
$content->setParts([$text, $html]);
$contentPart = new MimePart($content->generateMessage());
$contentPart->type = Mime::MULTIPART_ALTERNATIVE;
$contentPart->boundary = $content->getMime()->boundary();
$image = new MimePart(fopen($pathToImage, 'r'));
$image->type = 'image/jpeg';
$image->filename = 'image-file-name.jpg';
$image->disposition = Mime::DISPOSITION_ATTACHMENT;
$image->encoding = Mime::ENCODING_BASE64;
$body = new MimeMessage();
$body->setParts([$contentPart, $image]);
$message = new Message();
$message->setBody($body);
$contentTypeHeader = $message->getHeaders()->get('Content-Type');
$contentTypeHeader->setType('multipart/related');
In a multipart message, a MIME boundary for separating the different parts of
the message is normally generated at random. In some cases, however, you might
want to specify the MIME boundary that is used. This can be done by injecting a
new Laminas\Mime\Mime instance into the MIME message.
use Laminas\Mime\Mime;
$mimeMessage->setMime(new Mime($customBoundary));
How can I help you explore Laravel packages today?