Weave 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

Net Smtp Laravel Package

pear/net_smtp

PEAR Net_SMTP is a PHP SMTP client for sending email through SMTP servers, with support for authentication, TLS/SSL connections, and common SMTP options. A lightweight legacy PEAR component for projects that need direct mail transport.

Deep Wiki
Context7

Getting Started

Install it like any Composer package — PEAR's channel packages are mirrored on Packagist:

composer require pear/net_smtp

The package is a thin, protocol-level SMTP client, not a mailer. Read Net/SMTP.php first; the entire public surface is a dozen methods: connect(), auth(), mailFrom(), rcptTo(), data(), rset(), quit(), plus helpers like getResponse() and setDebug(). It does not build MIME messages (that is pear/mail_mime's job) and it does not speak to Laravel's Mail facade.

The fastest first use case is an SMTP connectivity/credentials probe, which is genuinely useful in a Laravel app (a php artisan smtp:check command):

use Net_SMTP;

$smtp = new Net_SMTP(config('mail.mailers.smtp.host'), (int) config('mail.mailers.smtp.port'));
$smtp->setDebug(false);

if (PEAR::isError($e = $smtp->connect())) {
    return $this->error($e->getMessage());
}

if (config('mail.mailers.smtp.username')) {
    $smtp->auth(
        config('mail.mailers.smtp.username'),
        config('mail.mailers.smtp.password')
    );
}

$smtp->quit();

If you only need to send mail, stop here and use Laravel's built-in Symfony Mailer transport. Reach for pear/net_smtp when you need raw SMTP dialogue that the framework abstracts away — probing, recipient verification, or integrating with an existing PEAR-based codebase.

Implementation Patterns

Custom Laravel transport. The realistic "day-to-day" integration is wrapping Net_SMTP in an Illuminate\Mail\Transport\Transport. This is useful when a mail provider requires an SMTP quirk the Symfony transport doesn't expose (unusual AUTH sequencing, custom EHLO hostname, pre-send NOOP).

namespace App\Mail\Transport;

use Illuminate\Mail\Transport\Transport;
use Net_SMTP;
use PEAR;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mime\RawMessage;

class NetSmtpTransport extends Transport
{
    public function __construct(private array $config) {}

    public function send(RawMessage $message, ?Envelope $envelope = null): ?SentMessage
    {
        $smtp = new Net_SMTP($this->config['host'], $this->config['port']);
        $smtp->setTimeOut($this->config['timeout'] ?? 30);

        if ($err = $smtp->connect()) {
            throw new \RuntimeException($err->getMessage());
        }

        if (!empty($this->config['username'])) {
            $smtp->auth($this->config['username'], $this->config['password']);
        }

        $smtp->mailFrom($this->config['from']['address']);
        foreach ($envelope->getRecipients() as $recipient) {
            $smtp->rcptTo($recipient->getAddress());
        }

        $smtp->data($message->toString());
        $smtp->quit();
    }
}

Register it in a service provider and point a mailer's driver at it. This keeps Mail::to(...)->send(...) and queued Mailables working while swapping the wire implementation.

Batch sends over one connection. Net_SMTP supports connection reuse; loop with mailFrom/rcptTo/data and call rset() between logical messages instead of reconnecting. Wrap the whole loop in a try/finally that calls quit() so a failed job doesn't leak sockets across a worker process.

Diagnostics that Laravel can't do. rcptTo() returning success is a real RCPT TO check — useful for list hygiene before enqueueing. Combine with Net_SMTP's response codes (250, 550, 451) to branch on soft vs hard bounces.

Legacy PEAR coexistence. If you're integrating code that uses Mail::factory('smtp', $params), keep pear/mail and pear/net_smtp on matching versions; Mail's SMTP driver is a thin façade over this exact class and will pass through connection options like timeout, localhost, and auth.

Gotchas and Tips

  • PEAR error handling, not exceptions. By default methods return PEAR_Error objects, not throws. Either check every return with PEAR::isError() or set raiseError to a callback and throw from there. Silent failures are the number one bug when people adopt this class in an exception-oriented codebase.
  • Implicit TLS (port 465) is not handled. Net_SMTP speaks STARTTLS (port 587) via its starttls option, but SMTPS on 465 requires you to build the ssl:// stream yourself or use a different client. Set 'ssl' => true in the socket options, or wrap the connection — otherwise you'll hang on connect().
  • auth() picks a mechanism by server advertisement. CRAM-MD5 and DIGEST-MD5 can be advertised but misconfigured; if auth fails unexpectedly, inspect the EHLO response with setDebug(true) and consider forcing PLAIN via the auth_methods option.
  • Do not replace Laravel's mailer wholesale. You lose Mailable templating, markdown rendering, events, and the MessageSending/MessageSent pipeline. Only swap the transport layer, as shown above, and keep Symfony MIME for message building.
  • Timeouts default low for queued workers. Set setTimeOut() explicitly; a stuck socket in a Horizon worker is a silent throughput killer. Pair with DB::transaction boundaries — never hold a DB transaction across an SMTP call.
  • data() expects CRLF-normalized, dot-stuffed input. The class handles dot-stuffing internally but expects you to provide correct \r\n line endings. Passing \n-only bodies from a template can produce malformed messages on strict servers.
  • Extension points are subclassing only. There is no middleware or event hook; if you need logging or header injection, extend Net_SMTP and override data() or mailFrom(). Keep subclasses small — the API is procedural and easy to break.
  • Version pinning matters. The 2026 release cadence means recent security and TLS fixes; pin a minimum version in composer.json and let Dependabot track it. With 26 stars, don't assume broad community debugging — read the source when something fails, it's a small file and is readable in an afternoon.
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator