Skip to content

Latest commit

 

History

History
103 lines (73 loc) · 3.86 KB

FAQ.md

File metadata and controls

103 lines (73 loc) · 3.86 KB

FAQ

mail() works locally but not in production — why?

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.

How do I send through Gmail / a typical provider?

$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.

send() doesn't return true anymore — how do I know it worked?

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.

My configuration array seems ignored.

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).

How do I attach a generated file (e.g. a PDF) without writing it to disk?

Use attachContent():

$mailer->attachContent($pdfBytes, 'invoice.pdf', 'attachment', 'application/pdf');

How do I embed an image in an HTML email?

Attach it as inline, get a CID, and reference it with cid: — see Attachments → inline images.

An address is rejected even though it looks valid.

Validation uses PHP's FILTER_VALIDATE_EMAIL. If you must accept an address it rejects, disable validation:

$mailer = Mailer::newInstance(['validate' => false]);

Security: validate => false removes 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 an InvalidAddressException whether 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 as setTo([$address]).

Non-Latin subjects or names look like =?UTF-8?Q?...?=.

That's correct — it is RFC 2047 encoding. Mail clients decode it back to the original text. See Encoding & Headers.

My HTML email body arrives empty or truncated.

That was a 1.x quoted-printable bug that truncated HTML bodies; it is fixed in 2.0. Upgrade to 2.0.

Should I use the facade or a Mailer instance?

The facade is convenient for quick, sequential sends. For testability and when composing several messages, prefer a plain Mailer instance per message.

How do I send to a large BCC list efficiently?

Use BCC batching (setBCC($list, $size)) so each delivery carries only a slice, and consider SMTP keep-alive to reuse one connection.

Can I test my mail code without a real server?

Yes — every side effect is injectable. See Testing.

Which PHP versions are supported?

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.