Skip to content

New Command: wp mail #210

@bhubbard

Description

@bhubbard

I know it's possible to send mail this way, but I want to suggest making wp mail a new command.

wp eval "wp_mail( 'test@example.org', 'My subject', 'My body' );"

While having the wp mail send will be useful, I actually thing the other subcommands might have more value for many developers.

Proposed subcommands:

  • wp mail send <to> <subject> <body> [--format=<text|html>]: A clean wrapper for wp_mail() to easily dispatch messages from the CLI.
  • wp mail test <to>: Sends a standard test message but temporarily forces PHPMailer's $phpmailer->SMTPDebug to output verbose connection logs to the terminal. This would be invaluable for debugging SMTP plugin configurations or server-level mail blocks.
  • wp mail status or wp mail config: Outputs a table showing the current mail configuration (e.g., whether a plugin is hooking into phpmailer_init, the default From address, and content type).

Describe alternatives you've considered
The current alternative is using wp eval 'wp_mail(...);', which works for simple sending but is messy for HTML/attachments and provides zero debugging feedback if the mail fails to send due to a configuration or SMTP error.

Additional context
Having this natively in WP-CLI would save significant time for developers troubleshooting deliverability issues, especially on headless setups or when verifying automated server deployments.

Example Code:

https://gist.github.com/bhubbard/6e35a4ea677207928cd53bfe6c75c857

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions