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 Laravel Package

pear/mail

PEAR Mail is a PHP library for composing and sending email via Mail(), SMTP, or sendmail. It provides a common interface for transports, supports headers and attachments, and integrates with PEAR for quick setup in legacy and modern PHP projects.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer: composer require pear/mail. This package is part of the PEAR ecosystem and provides an abstract interface for sending emails—currently supporting SMTP, sendmail, and the built-in PHP mail() function. Begin by instantiating the appropriate driver: Mail::factory('smtp', $params), Mail::factory('sendmail', $params), or Mail::factory('mail'). The factory method returns a Mail object with a send() method accepting recipients, headers, and body. For a minimal example using the mail driver:

require_once 'Mail.php';
$mail = Mail::factory('mail');
$headers = ['From' => 'you@example.com', 'Subject' => 'Test'];
$body = 'Hello, world!';
$mail->send('recipient@example.com', $headers, $body);

Check the PEAR Mail documentation or Mail.php source for supported driver options (e.g., SMTP host, port, auth).

Implementation Patterns

  • Abstraction Layer: Use Mail::factory() to decouple email transport logic—switch between SMTP, sendmail, or mail() via config without changing business code.
  • Template Integration: Combine with templating (e.g., Twig) to generate HTML/text bodies, then pass to send().
  • Bulk Sending: Iterate over recipient lists, personalizing headers/body and sending individually (note: PEAR Mail doesn’t batch—set up SMTP with persistent connections or a separate queue for high volume).
  • Error Handling: Capture PEAR_Error from send() and inspect getMessage() for debugging—e.g., SMTP rejection details.
  • Testing: Swap Mail::factory('mail') with a mock or log driver in tests; some projects use a custom wrapper class for easier substitution.

Gotchas and Tips

  • No Namespacing: This is legacy PEAR code—uses global namespace. Avoid conflicts by ensuring autoloading doesn’t interfere (e.g., no PSR-4 clash on Mail class name). Use Composer’s include-path autoloading carefully.
  • Deprecation Status: PEAR is largely unmaintained; consider modern alternatives like Symfony Mailer or Laravel’s built-in mailer for new projects—but this package remains functional for legacy support.
  • SMTP Auth: For SMTP, credentials are passed in the factory options array: ['host' => 'smtp.example.com', 'auth' => true, 'username' => '...', 'password' => '...'].
  • Headers Formatting: Recipient addresses in headers (e.g., To, Cc) must be properly RFC-compliant (e.g., "Name <email@example.com>"). Use Mail::normalizeRecipients() (if available) or Mail_RFC822::parseAddressList() from Mail_RFC822 package.
  • Missing Dependencies: Some drivers (e.g., SMTP) rely on Net_SMTP. Run composer require pear/net_smtp if you see “Class ‘Net_SMTP’ not found” errors.
  • No PSR-17/18 Support: This is pre-PSR mail handling—cannot directly integrate with PSR mail message implementations. Wrap if bridging legacy and modern code.
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