The mail transport only hands the message to whatever MTA the host's PHP is
configured to use. If that isn't set up (common on cloud hosts), nothing is
delivered even though send() succeeds. Use the SMTP transport
with your provider's server instead.
$mailer = Mailer::newInstance([
'protocol' => 'smtp',
'SMTPHost' => 'smtp.gmail.com',
'SMTPPort' => 587,
'SMTPCrypto' => 'tls',
'SMTPUser' => 'you@gmail.com',
'SMTPPass' => 'your-app-password',
]);Use a provider-issued app password, not your account password, where the provider requires one.
In 2.0 send() returns void and throws on failure. If it returns without
throwing, the message was handed off successfully. See
Error Handling and
Upgrading 1.x → 2.0.
That was a 1.x bug — the constructor silently dropped the array. It is fixed in
2.0. Make sure you are on 2.0 and that you are passing the array to
new Mailer($config) / Mailer::newInstance($config).
Use attachContent():
$mailer->attachContent($pdfBytes, 'invoice.pdf', 'attachment', 'application/pdf');Attach it as inline, get a CID, and reference it with cid: — see
Attachments → inline images.
Validation uses PHP's FILTER_VALIDATE_EMAIL. If you must accept an address it
rejects, disable validation:
$mailer = Mailer::newInstance(['validate' => false]);Security:
validate => falseremoves the format check on addresses, but not the character check. A CR, LF or NUL inside an address (user@example.com\r\nBcc: attacker@example.test), or a<or>inside an address (user@example.com> NOTIFY=NEVER), is rejected with anInvalidAddressExceptionwhether validation is on or off, so a request-supplied address cannot start another header or add parameters to an SMTP command. Only a leading or trailing line break is trimmed. A display name is never rejected: a line break or NUL in it is escaped or Q-encoded when the header is written, so it cannot start another header either. The check does not limit how many recipients a string names:"a@x.com,b@x.com"is two. Avoid turning validation off for addresses that come from user input, and pass a single untrusted address assetTo([$address]).
That's correct — it is RFC 2047 encoding. Mail clients decode it back to the original text. See Encoding & Headers.
That was a 1.x quoted-printable bug that truncated HTML bodies; it is fixed in 2.0. Upgrade to 2.0.
The facade is convenient for quick, sequential sends. For testability
and when composing several messages, prefer a plain Mailer instance per
message.
Use BCC batching (setBCC($list, $size)) so each
delivery carries only a slice, and consider
SMTP keep-alive to reuse one connection.
Yes — every side effect is injectable. See Testing.
PHP 8.2, 8.3, 8.4, 8.5 and 8.6 are tested in CI, with ext-mbstring,
ext-iconv and ext-fileinfo enabled.