Documentation

MailerProxy extends PHPMailer
in package

FinalYes

PHPMailerWrapper

  • Subclass of PHPMailer to keep a single instantiation and extend with helpers.
  • Constructor accepts options (array|object) and an optional PSR-3 logger.
  • Provides convenient methods: configureSMTP, setDKIM, sendHtml, sendText, sendLoop, sendOnce (test mode aware), etc.

Table of Contents

Properties

$from  : array<string|int, mixed>|null
$lastError  : string|null
$logger  : LoggerInterface
$opts  : array<string|int, mixed>
$testMode  : bool

Methods

__construct()  : mixed
__destruct()  : mixed
closeSmtp()  : void
configureSMTP()  : void
Configure SMTP options.
getLastError()  : string|null
Return last error message (if any).
getToAddresses()  : array<string|int, mixed>
Helper: return simplified list of recipients for logging
isTestMode()  : bool
resetForNext()  : void
Clear recipients and attachments to prepare for next send.
send()  : bool
Override send() to support test mode and consistent logging.
sendHtml()  : bool
Send HTML email to single recipient (quick helper).
sendLoop()  : array<string|int, mixed>
Send multiple envelopes reusing the same PHPMailer instance (no internal new() per message).
sendText()  : bool
Send plain text email to single recipient (quick helper).
setDKIM()  : void
Set DKIM options for PHPMailer.
setTestMode()  : void
Enable / disable test mode.
setTransport()  : void
Set transport: 'smtp'|'mail'|'sendmail'
normalizeOptions()  : array<string|int, mixed>
splitAddressAndName()  : array<string|int, mixed>
Split "Name <email>" or "email" into [email,name]

Properties

$from

protected array<string|int, mixed>|null $from = null

from address and name

$lastError

protected string|null $lastError = null

last error message

$opts

protected array<string|int, mixed> $opts = []

Normalized options

$testMode

protected bool $testMode = false

If true, do not actually call network send; used for testing.

Methods

__construct()

public __construct([array<string|int, mixed>|object|null $options = null ][, LoggerInterface|null $logger = null ][, bool $exceptions = true ]) : mixed
Parameters
$options : array<string|int, mixed>|object|null = null

SMTP / behavior options (see configureSMTP)

$logger : LoggerInterface|null = null

PSR-3 logger; if null, NullLogger is used

$exceptions : bool = true

pass to PHPMailer constructor (enable exceptions)

configureSMTP()

Configure SMTP options.

public configureSMTP(array<string|int, mixed>|object $cfg) : void

Expected keys in $cfg: host, port, username, password, encryption ('ssl'|'tls'), smtp_auth (bool), timeout (int), keepalive (bool), smtp_options (array for PHPMailer's SMTPOptions)

Parameters
$cfg : array<string|int, mixed>|object

getLastError()

Return last error message (if any).

public getLastError() : string|null
Return values
string|null

getToAddresses()

Helper: return simplified list of recipients for logging

public getToAddresses() : array<string|int, mixed>
Return values
array<string|int, mixed>

isTestMode()

public isTestMode() : bool
Return values
bool

resetForNext()

Clear recipients and attachments to prepare for next send.

public resetForNext() : void

send()

Override send() to support test mode and consistent logging.

public send() : bool
Return values
bool

sendHtml()

Send HTML email to single recipient (quick helper).

public sendHtml(string $to, string $subject, string $html[, string|null $from = null ][, string|null $alt = null ][, string|null $addReplyTo = null ][, array<string|int, mixed>|null $addStringAttachments = null ][, array<string|int, mixed>|null $addEmbeddedImage = null ]) : bool
Parameters
$to : string

email or "Name "

$subject : string
$html : string
$from : string|null = null

optional from "Name "

$alt : string|null = null
$addReplyTo : string|null = null
$addStringAttachments : array<string|int, mixed>|null = null
$addEmbeddedImage : array<string|int, mixed>|null = null
Return values
bool

sendLoop()

Send multiple envelopes reusing the same PHPMailer instance (no internal new() per message).

public sendLoop(array<string|int, mixed> $envelopes) : array<string|int, mixed>

Each envelope: [ 'to' => ['email' or 'Name ' or ['email','name'], ...], 'subject' => string, 'body' => string, 'is_html' => bool (optional), 'from' => 'Name ' or ['email','name'] (optional), 'attachments' => [ ['path','name'] , ... ], 'headers' => ['X-Header' => 'value', ...] ]

Returns array ['ok'=>int,'failed'=>int]

Parameters
$envelopes : array<string|int, mixed>
Return values
array<string|int, mixed>

sendText()

Send plain text email to single recipient (quick helper).

public sendText(string $to, string $subject, string $text[, string|null $from = null ][, string|null $alt = null ][, string|null $addReplyTo = null ][, array<string|int, mixed>|null $addStringAttachments = null ][, array<string|int, mixed>|null $addEmbeddedImage = null ]) : bool
Parameters
$to : string
$subject : string
$text : string
$from : string|null = null
$alt : string|null = null
$addReplyTo : string|null = null
$addStringAttachments : array<string|int, mixed>|null = null
$addEmbeddedImage : array<string|int, mixed>|null = null
Return values
bool

setDKIM()

Set DKIM options for PHPMailer.

public setDKIM(array<string|int, mixed> $opts) : void

$opts should include: domain, selector, private_key_file, passphrase (optional)

Parameters
$opts : array<string|int, mixed>

setTestMode()

Enable / disable test mode.

public setTestMode([bool $on = true ]) : void

When enabled, send() will not call network and will return true (after logging).

Parameters
$on : bool = true

setTransport()

Set transport: 'smtp'|'mail'|'sendmail'

public setTransport(string $mode) : void
Parameters
$mode : string

normalizeOptions()

protected normalizeOptions(array<string|int, mixed>|object|null $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>|object|null
Return values
array<string|int, mixed>

splitAddressAndName()

Split "Name <email>" or "email" into [email,name]

protected splitAddressAndName(string $input) : array<string|int, mixed>
Parameters
$input : string
Return values
array<string|int, mixed>
On this page

Search results