Make WordPress Core

Changeset 52083


Ignore:
Timestamp:
11/09/2021 10:25:40 PM (3 years ago)
Author:
davidbaumwald
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r52065 r52083  
    538538        do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
    539539
     540        $mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
     541
    540542        // Send!
    541543        try {
    542             return $phpmailer->send();
     544            $send = $phpmailer->send();
     545
     546            /**
     547             * Fires after PHPMailer has successfully sent a mail.
     548             *
     549             * The firing of this action does not necessarily mean that the recipient received the
     550             * email successfully. It only means that the `send` method above was able to
     551             * process the request without any errors.
     552             *
     553             * @since 5.9.0
     554             *
     555             * @param array $mail_data An array containing the mail recipient, subject, message, headers, and attachments.
     556             */
     557            do_action( 'wp_mail_succeeded', $mail_data );
     558
     559            return $send;
    543560        } catch ( PHPMailer\PHPMailer\Exception $e ) {
    544 
    545             $mail_error_data                             = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
    546             $mail_error_data['phpmailer_exception_code'] = $e->getCode();
     561            $mail_data['phpmailer_exception_code'] = $e->getCode();
    547562
    548563            /**
     
    554569             *                        containing the mail recipient, subject, message, headers, and attachments.
    555570             */
    556             do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
     571            do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) );
    557572
    558573            return false;
Note: See TracChangeset for help on using the changeset viewer.