Make WordPress Core

Opened 22 months ago

Closed 19 months ago

Last modified 17 months ago

#53826 closed enhancement (fixed)

wp_mail_succeeded action in wp_mail()

Reported by: birgire's profile birgire Owned by: davidbaumwald's profile davidbaumwald
Milestone: 5.9 Priority: normal
Severity: normal Version:
Component: Mail Keywords: has-patch commit has-dev-note
Focuses: Cc:


To complement the wp_mail_failed action in wp_mail() we could add the wp_mail_succeeded action.

Here's a suggestion to use e.g.:

$status = $phpmailer->send();

if ( $status ) {

	$mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );

	 * Fires after PHPMailer has successfully sent a mail.
	 * @since x.y.z
	 * @param array $mail_data An array containing the mail recipient, subject, message, headers, and attachments.
	do_action( 'wp_mail_succeeded', $mail_data );		

in wp_mail() instead of:

return $phpmailer->send();

ps: In BuddyPress we have e.g. both bp_send_email_failure and bp_send_email_success actions.

Attachments (1)

53826.diff (1.8 KB) - added by davidbaumwald 19 months ago.
Added disclaimer, minor spelling corrections

Download all attachments as: .zip

Change History (13)

This ticket was mentioned in PR #1535 on WordPress/wordpress-develop by donmhico.

22 months ago

  • Keywords has-patch added

This PR adds wp_mail_succeeded action.

Trac ticket:

#2 @birgire
22 months ago

@donmhico Thanks for the patch, it looks good.

#3 @SergeyBiryukov
22 months ago

  • Milestone changed from Awaiting Review to 5.9

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.

19 months ago

#5 @hellofromTonya
19 months ago

  • Milestone changed from 5.9 to Future Release

Looking at the new action, 'wp_mail_succeeded', why is it in the catch and not the try? If it succeeds, it would not go into the catch.

Today is 5.9 feature freeze. With questions pending, punting this one to 6.0. As that milestone isn't available yet, setting it to Future Release. Once available, please feel free to move it into the milestone.

#6 @davidbaumwald
19 months ago

@hellofromTonya From what I can tell, the patch is good. The wp_mail_succeeded action is in the try section, and the wp_mail_failed action is in the catch.

Whether or not this can be pulled back in for 5.9 is another question, but did want to clear up the the current PR looks OK.

#7 @hellofromTonya
19 months ago

  • Keywords commit added
  • Milestone changed from Future Release to 5.9

@davidbaumwald you're right. Picture me doing a facepalm (doh). Pulling it back in and marking for commit.

#8 @davidbaumwald
19 months ago

  • Owner set to davidbaumwald
  • Status changed from new to reviewing

@hellofromTonya Thanks! I'll pick this one up for review and commit.

19 months ago

Added disclaimer, minor spelling corrections

#9 @davidbaumwald
19 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 52083:

Mail: Add wp_mail_succeeded hook to wp_mail.

Adds a new wp_mail_succeeded action in wp_mail after the mail is sent. Also, adds a disclaimer to the hook's docblock, clarifying that the hook's firing doesn't necessarily mean the recipient received the mail, only that the mail was processed without any errors.

Props birgire, donmhico, johnbillion.
Fixes #53826.

dream-encode commented on PR #1535:

19 months ago

Committed to core via changeset:

#11 @davidbaumwald
19 months ago

  • Keywords needs-dev-note added

Marking this with needs-dev-note for a small call-out on the Misc Dev note for the new filter.

#12 @audrasjb
17 months ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.