Repository navigation
Configuration
A mailer is configured once, with an array passed to the constructor or
newInstance(). The keys keep the spelling they have had since 1.x
(SMTPHost, mailType, CRLF, …). Every key has a default, unknown keys are
ignored, and the values are normalised and validated as they are read.
use InitPHP\Mailer\Mailer;
$mailer = Mailer::newInstance([
'protocol' => 'smtp',
'SMTPHost' => 'smtp.example.com',
'SMTPUser' => 'you@example.com',
'SMTPPass' => 'secret',
'SMTPPort' => 587,
'SMTPCrypto' => 'tls',
'charset' => 'UTF-8',
'priority' => 1,
]);In 1.x the constructor silently ignored the array. In 2.0 the configuration is always applied — this is the headline fix of the release.
| Key | Type | Default | Description |
|---|---|---|---|
fromEmail |
string | '' |
Sender used when setFrom() is not called. |
fromName |
string | '' |
Display name paired with fromEmail. |
mailType |
string | 'text' |
'text' or 'html'. |
charset |
string | 'UTF-8' |
Character set; stored upper-cased. A CR, LF or NUL throws a ConfigurationException. |
priority |
int | 3 |
X-Priority, 1 (highest)–5 (lowest); out-of-range → 3. |
altMessage |
string | '' |
Plain-text alternative for HTML messages. |
userAgent |
string | 'InitPHP Mailer' |
User-Agent / X-Mailer header value. A CR, LF or NUL throws a ConfigurationException. |
validate |
bool | true |
Validate addresses as they are added. Turning it off removes the format check only; a CR, LF, NUL, < or > in an address is rejected either way — see Error Handling. |
| Key | Type | Default | Description |
|---|---|---|---|
protocol |
string | 'mail' |
'mail', 'sendmail' or 'smtp'; anything else → 'mail'. |
mailPath |
string | '/usr/sbin/sendmail' |
Path to the sendmail binary (sendmail only). |
See Transports.
| Key | Type | Default | Description |
|---|---|---|---|
SMTPHost |
string | '' |
SMTP server host. |
SMTPPort |
int | 25 |
SMTP server port. |
SMTPUser |
string | '' |
Username for AUTH LOGIN. |
SMTPPass |
string | '' |
Password for AUTH LOGIN. |
SMTPAuth |
bool | derived | Authenticate? Defaults to true when both user and pass are set. |
SMTPCrypto |
string | '' |
'', 'tls' (STARTTLS) or 'ssl' (implicit TLS). |
SMTPTimeout |
int | 5 |
Connection/read timeout, in seconds. |
SMTPKeepAlive |
bool | false |
Reuse one connection for several messages. |
DSN |
bool | false |
Request Delivery Status Notifications. |
See SMTP Transport.
| Key | Type | Default | Description |
|---|---|---|---|
wordWrap |
bool | true |
Word-wrap plain-text bodies. |
wrapChars |
int | 76 |
Column to wrap at. |
sendMultipart |
bool | true |
Send multipart/alternative for HTML messages. |
newline |
string | PHP_EOL |
Header line ending ("\n", "\r\n", "\r"). |
CRLF |
string | "\n" |
Body line ending for the quoted-printable encoder. |
See Encoding & Headers.
| Key | Type | Default | Description |
|---|---|---|---|
BCCBatchMode |
bool | false |
Split a large BCC list into several messages. |
BCCBatchSize |
int | 200 |
Maximum BCC recipients per message. |
See Sending Mail → BCC batching.
The configuration object cleans up the values you pass, so a slightly-off value never produces a broken message:
-
charsetis upper-cased (utf-8→UTF-8). -
protocolis lower-cased and must be one ofmail/sendmail/smtp, otherwise it falls back tomail. -
mailTypeishtmlonly for the exact (case-insensitive) valuehtml, otherwisetext. -
priorityoutside 1–5 falls back to3. -
SMTPCryptoother thantls/sslbecomes''(no encryption). -
newline/CRLFoutside the four recognised endings fall back to the default. -
SMTPAuthdefaults totruewhen bothSMTPUserandSMTPPassare set.
Most options are fixed once the mailer is built, but a few have setters so they can vary per message:
| Setter | Equivalent config |
|---|---|
setProtocol() |
protocol |
setMailType() |
mailType |
setPriority() |
priority |
setWordWrap() |
wordWrap |
setAltMessage() |
altMessage |
setNewline() |
newline |
setCRLF() |
CRLF |
setBCC($list, $limit) |
BCCBatchMode + BCCBatchSize
|
initphp/mailer · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Sending
Reliability
Reference
Migration