Repository navigation
API Reference
The full public surface of InitPHP\Mailer\Mailer, plus the facade, exceptions
and transport types. Signatures are taken straight from the source.
All set*/attach*/clear methods return the Mailer (self) so they chain.
Builds a mailer from an optional configuration array.
Convenience factory; identical to new Mailer($config) but reads well in a
chain.
$mailer = Mailer::newInstance(['protocol' => 'smtp', /* … */]);
Sets the sender. $from may be address or "Name" <address>; $name wins
over an embedded name. $returnPath sets the envelope sender.
Throws InvalidAddressException — also when the address, the name or
$returnPath contains a CR, LF or NUL, whatever the validate option says.
Sets the Reply-To. Defaults to the sender when never called.
Throws InvalidAddressException (also for a CR, LF or NUL, even with
validate off).
Sets the To recipients. Accepts one address, a comma/space-separated string, or
an array. Throws InvalidAddressException. An address containing a CR, LF or
NUL is rejected even with validate off; in a string, whitespace (including line
breaks) still separates addresses.
Sets the CC recipients. Throws InvalidAddressException (same line-break
rule as setTo()).
Sets the BCC recipients. A non-null $limit enables BCC batching
with that batch size. Throws InvalidAddressException (same line-break rule as
setTo()).
Sets the subject. Encoded (RFC 2047 Q) automatically when it contains non-ASCII.
CR and LF are removed when the message is built; a NUL is Q-encoded (=00).
Sets the body (plain text or HTML depending on the mail type). Carriage returns are stripped and surrounding blank lines trimmed.
Sets the plain-text alternative used for HTML messages. Carriage returns are
stripped, like in setMessage().
'html' for the value html (case-insensitive), otherwise 'text'.
Attaches a file from disk. $disposition defaults to attachment (use inline
for embedded images), $newName overrides the displayed name, $mime skips
auto-detection. Throws AttachmentException, also when the name, disposition
or MIME type contains a CR, LF or NUL.
attachContent(string $content, string $name, string $disposition = 'attachment', ?string $mime = null): self
Attaches in-memory/generated content. $mime defaults to
application/octet-stream. Throws AttachmentException when the name,
disposition or MIME type contains a CR, LF or NUL.
Promotes a previously added attachment (matched by its path/name) to an inline
related part and returns its generated Content-ID.
Throws AttachmentException when no attachment matches.
Adds a custom header. CR, LF and NUL are stripped from the value. A header the
library writes for the message itself (From, Subject, Cc with CC recipients, Bcc
with BCC recipients on sendmail and mail(), Date, Message-ID, …) wins over a
custom one of the same name, whatever the case or spacing; one it does not write
is kept as you set it. To is not special-cased and behaves as it always did
(see Custom headers). Use
setTo()/setCC()/setBCC() for recipients, not headers.
Throws MailerException when the header name is not printable ASCII
without :, a tab or an inner space.
X-Priority, 1 (highest)–5 (lowest); out-of-range → 3.
Enables/disables word-wrapping of plain-text bodies.
Word-wraps a string at $chars columns (or the configured width). Honours
{unwrap}…{/unwrap} markers.
Header line ending; one of "\n", "\r\n", "\n\r", "\r" (else PHP_EOL).
Body (quoted-printable) line ending; same accepted set.
Returns a unique Message-ID based on the sender domain.
'mail', 'sendmail' or 'smtp' (else 'mail').
Builds and sends the message. Clears per-message state afterwards unless
$autoClear is false.
Throws ConfigurationException (missing sender/recipient/SMTP host),
InvalidAddressException (invalid configured sender), TransportException
(delivery failure).
Resets per-message state. Pass true to also drop attachments.
A credential-free snapshot of the last sent message, or null before the first
send.
HTML dump of the last built headers/subject/body. Restrict with the $include
list.
Whether one address is valid.
Whether every address in the list is valid.
Overrides the protocol-derived transport (used in Testing).
Overrides the MIME boundary generator: callable(string $prefix): string.
send() throws a MailerException for an empty boundary or one containing a
quote, CR, LF or NUL.
Static proxy to a shared Mailer. Every instance method above is callable
statically.
Sets (or resets, with null) the shared instance. See Facade.
| Class | Extends |
|---|---|
MailerException |
\RuntimeException |
ConfigurationException |
MailerException |
InvalidAddressException |
MailerException |
AttachmentException |
MailerException |
TransportException |
MailerException (code = SMTP reply / sendmail exit) |
See Error Handling.
| Type | Role |
|---|---|
TransportInterface |
send(PreparedEmail $email): void |
MailTransport |
mail(); __construct(EmailValidator $v, ?callable $mailFunction = null)
|
SendmailTransport |
sendmail pipe; __construct(string $mailPath, EmailValidator $v, ?callable $pipe = null)
|
SmtpTransport |
SMTP over a SocketClientInterface
|
Smtp\SocketClientInterface |
the socket abstraction |
Smtp\StreamSocketClient |
default fsockopen()-based socket |
See Transports and Testing.
initphp/mailer · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Sending
Reliability
Reference
Migration