Skip to content

Core Concepts

WireMailPHPMailer is a non-singular (singular => false), lazy-loaded (autoload => false) WireMail module so each $wire->mail->new() call receives a clean message instance.

flowchart TD
    A["Caller invokes $wire->mail->new()"] --> B["WireMailPHPMailer::init()"]
    B --> C["Set to(), cc(), bcc(), subject(), body(), bodyHTML(), attachment()"]
    C --> D["WireMailPHPMailer::___send()"]
    D --> E{"$config->demo active?"}
    E -- Yes --> F["Abort safely and return 0"]
    E -- No --> G["getInstance() builds PHPMailer v7 (SMTP / DSN / XOAUTH2 / DKIM)"]
    G --> H["Deliver message & reset state in finally block"]
    H --> I["Return sent recipient count (int)"]

___send() returns the integer count of recipients delivered (0 on error or when $config->demo is enabled) and always resets internal PHPMailer recipient/attachment state inside a finally block so a reused instance can never leak recipients or attachments to a subsequent email.

2. Six-Tab Configuration (WireMailPHPMailerConfig)

Section titled “2. Six-Tab Configuration (WireMailPHPMailerConfig)”

All transport settings live in Modules -> Configure -> WireMailPHPMailer, organized into six focused tabs:

  • TabGeneral: Default From address/name, charset, encoding, and content defaults.
  • TabRouting: Reply-To, Return-Path, and routing defaults.
  • TabTransport: Transport selector (SMTP, Sendmail, mail()), dsn, host, port, encryption, credentials, and OAuth2 settings.
  • TabDKIM: Domain, selector, identity, private key string/file, and passphrase.
  • TabAdvanced: Timeout, TLS peer verification, SMTP keep-alive, and Debugoutput (defaults to 'error_log').
  • TabTest: Built-in live test email sender (automatically disabled when $config->demo is active).

3. Pluggable PHPMailer Instance (getInstance() & setMailer())

Section titled “3. Pluggable PHPMailer Instance (getInstance() & setMailer())”
  • getInstance(bool $initialize = true, bool $exceptions = false) returns the configured PHPMailer transport object for advanced customization.
  • setMailer(?PHPMailer $mailer) injects a custom transport or test double in Pest/PHPUnit tests so mail flows can be verified with zero network calls.

Next steps