Search by

Lightweight PHP 8.1+ email client: SMTP with STARTTLS/implicit TLS and PLAIN/LOGIN/CRAM-MD5/XOAUTH2 login, PHP mail(), and the Brevo, SendGrid, Mailgun, Postmark, Resend and Amazon SES APIs, behind one message and provider interface.

Package info

github.com/CallismartLtd/Mail

pkg:composer/callismart/mail

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-30 09:31 UTC

This package is auto-updated.

Last update: 2026-11-30 09:52:05 UTC


README

Send email from PHP over SMTP, PHP mail(), or the Brevo, SendGrid, Mailgun, Postmark, Resend and Amazon SES APIs, with one message object and one provider interface.

composer require callismart/mail

Requires PHP 8.1+, callismart/dto and callismart/http (used by the API providers only). SMTP over TLS needs ext-openssl.

Sending

use Callismart\Mail\EmailMessage;
use Callismart\Mail\Mailer;
use Callismart\Mail\Providers\SMTPProvider;

$smtp = new SMTPProvider( 'Acme', 'no-reply@acme.test' );
$smtp->set_settings( [
	'host'       => 'smtp.acme.test',
	'port'       => 587,
	'encryption' => 'starttls',
	'username'   => 'no-reply@acme.test',
	'password'   => 'app password',
] );

$response = ( new Mailer( $smtp ) )->send( new EmailMessage( [
	'to'          => 'customer@example.com',
	'subject'     => 'Your licence key',
	'body'        => '<p>Here is your key…</p>',
	'text'        => 'Here is your key…',
	'attachments' => [ '/path/to/invoice.pdf' ],
] ) );

$response->get( 'message_id' );

Or fluently: Mailer::with_provider( $smtp )->to( … )->subject( … )->body( … )->send().

Failures throw Exceptions\EmailTransportException (a RuntimeException). is_transient() says whether retrying later can work (SMTP 4xx such as greylisting, lost connections, HTTP 429/5xx); get_smtp_code() returns the server's reply code. Invalid settings or addresses throw InvalidArgumentException.

Providers

ID Class Needs
smtp Providers\SMTPProvider an SMTP server
php_mail Providers\PHPMailProvider a working mail()
brevo, sendgrid, mailgun, postmark, resend, amazon_ses Providers\…Provider an API key and an HttpClient

Every provider implements Providers\EmailProviderInterface: get_id(), get_name(), get_settings_schema() (field definitions to build a settings form), set_settings() and send().

SMTP compatibility

SMTPProvider is tested against servers old and new (tests/):

  • Encryption: ssl (implicit TLS, port 465), starttls (587/25), tls (implicit on 465, STARTTLS elsewhere), or none.
  • Old servers: falls back from EHLO to HELO; reads reply codes with no text (250), multi-line greetings, bare-LF line endings, AUTH= lines and 251 replies; tls_legacy allows TLS 1.0/1.1 for servers with nothing newer.
  • Login: PLAIN (empty authzid), LOGIN, CRAM-MD5 and XOAUTH2 (password = OAuth 2.0 access token). "Automatic" picks from what the server offers and moves on only when a method is unsupported, never after wrong credentials.
  • Certificates are verified by default. tls_ca_file trusts a private CA, tls_peer_name sets the expected name, tls_verify = no accepts self-signed certificates.
  • Messages are 7-bit: RFC 2047 encoded and folded headers, quoted-printable text, base64 attachments streamed from disk, RFC 2231 file names, dot-stuffing. CR/LF in header values is removed, so headers cannot be injected.
  • One connection is reused across send() calls (close() ends it), checked with NOOP after it has been idle, and reset with RSET after a rejection.
Setting Default
host, port –, 587 host name or IP (IPv6 with or without brackets)
encryption '' ssl, tls, starttls or ''
auth_mechanism '' (automatic) plain, login, cram-md5, xoauth2
username, password '' used exactly as given; no login when either is empty
from_email, from_name constructor defaults used when the message has no from
timeout 15 seconds, for connecting and for each reply
helo_hostname detected FQDN or [ip]
tls_verify yes
tls_ca_file, tls_peer_name ''
tls_legacy no

For tests, pass a Smtp\ConnectorInterface as the third constructor argument.

Translation

Labels, descriptions and error messages are English. To translate them, give the library a callback; it receives the English text:

Callismart\Mail\Translation::set_translator( fn ( string $text ) : string => my_translate( $text ) );

Tests

composer install
vendor/bin/phpunit                    # unit and integration
vendor/bin/phpunit --testsuite unit   # no sockets or OpenSSL needed

The integration suite starts a local SMTP server in a child process and runs STARTTLS, implicit TLS and the certificate checks through OpenSSL.

Licence

MIT