PHP API, Hooks & Troubleshooting
Resolve WireMailPHPMailer via $this->wire()->mail->new() (recommended) or $this->wire()->modules->get('WireMailPHPMailer').
ProcessWire\WireMailPHPMailer Method Reference
Section titled “ProcessWire\WireMailPHPMailer Method Reference”| Method | Signature | Description |
|---|---|---|
init |
$mail->init(): void |
Initializes default mail properties and module state. |
to |
$mail->to(string|array|null $email = null, ?string $name = null): static |
Sets recipient(s); passing null clears to, cc, and bcc. |
cc |
$mail->cc(string|array|null $email = null, ?string $name = null): static |
Sets or clears CC recipient(s). |
bcc |
$mail->bcc(string|array|null $email = null, ?string $name = null): static |
Sets or clears BCC recipient(s). |
attachment |
$mail->attachment(string|array|null $value, string $filename = ''): static |
Attaches validated local file(s); rejects wrappers, null bytes, .., symlinks, and site/config*.php. |
set |
$mail->set(string $key, mixed $value): static |
Sets standard WireMail keys, cc, bcc, attachments, or PHPMailer overrides. |
get |
$mail->get(string $key): mixed |
Retrieves a stored property (cc, bcc, attachments, or parent WireMail key). |
getArray |
$mail->getArray(): array |
Returns all mail properties including cc and bcc. |
setMailer |
$mail->setMailer(?PHPMailer $mailer): static |
Injects a custom PHPMailer instance or test double. |
getInstance |
$mail->getInstance(bool $initialize = true, bool $exceptions = false): PHPMailer |
Builds or resets and configures a PHPMailer v7 instance from module config. |
redactDsnCredentials |
WireMailPHPMailer::redactDsnCredentials(string $text): string |
Scrubs smtp:// / smtps:// userinfo credentials from log/error strings. |
___send |
$mail->send(): int |
Hookable send method; returns delivered recipient count (0 on failure or $config->demo), resets state in finally. |
Totoglu\WireMailPHPMailer\OAuthProvider Methods
Section titled “Totoglu\WireMailPHPMailer\OAuthProvider Methods”label(): stringpackageName(): stringproviderClass(): stringauthorizationOptions(): arrayisInstalled(): boolhasRequiredCredentials(string $clientId, string $clientSecret): boolcreateProvider(array $config): ?object
Hookable Methods (WireMailPHPMailer::___*)
Section titled “Hookable Methods (WireMailPHPMailer::___*)”| Hook | Arguments & Return | Timing | What It Does |
|---|---|---|---|
WireMailPHPMailer::send |
(): int |
Before / After | Dispatches the prepared email via PHPMailer and returns the delivered recipient count (0 on failure or $config->demo). Hook Before to inject headers or reroute staging recipients, or After to log delivery outcomes. |
Inject Global Headers & Log Delivery Outcomes
Section titled “Inject Global Headers & Log Delivery Outcomes”<?php
declare(strict_types=1);
namespace ProcessWire;
$wire->addHookBefore('WireMailPHPMailer::send', static function (HookEvent $event): void { /** @var WireMailPHPMailer $mail */ $mail = $event->object; $mail->header('X-Environment', 'production');});
$wire->addHookAfter('WireMailPHPMailer::send', static function (HookEvent $event): void { /** @var WireMailPHPMailer $mail */ $mail = $event->object; $sentCount = (int) $event->return; $event->wire()->log->save( 'mail-delivery', sprintf('Subject "%s" delivered to %d recipient(s).', (string) $mail->subject, $sentCount) );});Troubleshooting
Section titled “Troubleshooting”send() Returns 0 Immediately
Section titled “send() Returns 0 Immediately”Symptom: $mail->send() returns 0 with no SMTP network activity.
Fix:
- Check whether
$config->demoistrueinsite/config.php(WireMailPHPMailerblocks delivery in demo mode). - Confirm at least one valid
to()recipient andfrom()address are configured. - Inspect your PHP
error_log(defaultDebugoutput) for the redacted SMTP error message.
Attachment Rejected Silently
Section titled “Attachment Rejected Silently”Symptom: An expected PDF or CSV attachment is missing from the delivered email.
Fix: Verify the file exists on disk, is not a symlink (!is_link($path)), contains no .. segments or stream wrappers, and does not match site/config*.php.