Skip to content

New Command: wp mail #210

Open
Open

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

Activity

  1. swissspidy commented on Feb 21, 2026

    @swissspidy
    Member

    Previously:

    Thanks for sharing some working code alongside your feature request!

    For debugging or scripting purposes I agree some more verbose output like that could be useful.

    Have you successfully used that command yourself on your sites?

  2. bhubbard commented on Feb 23, 2026

    @bhubbard
    Author

    @swissspidy I have done something similar in the past. This code was AI generated, and I tested this command on 2 of our sites, and they seem to work great. I didn't do as a PR because I thought it could use more eyes and probably discussion first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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