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.
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).
Mail::factory() to decouple email transport logic—switch between SMTP, sendmail, or mail() via config without changing business code.send().PEAR_Error from send() and inspect getMessage() for debugging—e.g., SMTP rejection details.Mail::factory('mail') with a mock or log driver in tests; some projects use a custom wrapper class for easier substitution.Mail class name). Use Composer’s include-path autoloading carefully.['host' => 'smtp.example.com', 'auth' => true, 'username' => '...', 'password' => '...'].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.Net_SMTP. Run composer require pear/net_smtp if you see “Class ‘Net_SMTP’ not found” errors.How can I help you explore Laravel packages today?