Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mail Mime Laravel Package

pear/mail_mime

PEAR Mail_mime builds MIME-encoded email messages in PHP. Create multipart/alternative and mixed emails with plain text and HTML bodies, add attachments and inline images, and generate headers and bodies ready to send via Mail or other transports.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require pear/mail_mime. This is a legacy PEAR package, so verify your environment supports it (PHP 5.x–7.4; not compatible with PHP 8+ in most cases). Begin by instantiating Mail_Mime, then set text/HTML bodies and add attachments:

use Mail_Mime;

$message = new Mail_Mime("\n");
$message->setTXTBody('Plain text version');
$message->setHTMLBody('<p>HTML <strong>version</strong></p>');
$message->addAttachment('report.pdf', 'application/pdf', 'Monthly Report');

$body = $message->get();
$headers = $message->getHeaders([
    'From'    => 'sender@example.com',
    'To'      => 'recipient@example.com',
    'Subject' => 'Your Report',
]);

Send using PEAR::Mail (Mail::factory('smtp')), or wrap $body + $headers into Symfony Mailer or PHPMailer if needed. Start with the examples/ directory in the package source — it’s more reliable than sparse online docs.

Implementation Patterns

  • Dual-format emails: Always pair setTXTBody() and setHTMLBody() for accessibility and spam score — Mail_Mime auto-generates multipart/alternative boundaries correctly.
  • Inline images in HTML: Use addHTMLImage($path, $mimetype, $cid) and reference <img src="cid:$cid"> in HTML body. Critical: CID must match exactly — no extra quotes or casing differences.
  • Large file streaming: Prefer addFile($filepath, $mimetype, $filename) over addAttachment($content, ...) to avoid memory exhaustion on big attachments.
  • Custom headers: Pass extra headers (e.g., Reply-To, List-Unsubscribe) as key-value to getHeaders(). Important: Manually encode non-ASCII header values using mb_encode_mimeheader() first.
  • Bridge to modern mailers: Use Mail_Mime only for composition, then inject $body and $headers into Symfony’s RawMessage or PHPMailer for sending — avoids tight coupling to deprecated transports.

Gotchas and Tips

  • Line endings matter: Default \n is safe for mail() and most PHP mail functions, but SMTP requires \r\n — use Mail_Mime::CRLF only when sending via Net_SMTP or configured PEAR::Mail SMTP transport.
  • No auto header encoding: Subject, From, To headers must be manually encoded (e.g., mb_encode_mimeheader($subject, 'UTF-8', 'B')) — unencoded non-ASCII chars break delivery.
  • MIME boundaries are opaque: You can’t manually tweak boundaries. Avoid inspecting $body to debug — it’s opaque and fragile.
  • Deprecated PEAR dependencies: Requires Mail, Net_SMTP, PEAR core — ensure no conflicts with Composer-installed packages (e.g., php-pear/pear-core-minimal may be needed).
  • Debug mode: Enable with Mail_Mime::setDebug(true) or override Mail_Mime::setDebugCallback() to capture verbose logging for troubleshooting misrendered emails.
  • PHP 8+ failure mode: This package is unmaintained since ~2015. On PHP 8+, expect fatal errors due to type hints, removed globals ($HTTP_RAW_POST_DATA), and PEAR autoloader incompatibility — avoid in new environments.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport