wp_mail_succeeded
Fires after an email has been sent (PHPMailer sent the email), allowing an action to be performed.
This event firing does not mean that the recipient successfully received the email. It means only that PHPMailer::send was able to process the request without errors.
Usage
add_action( 'wp_mail_succeeded', 'wp_kama_mail_succeeded_action' );
/**
* Function for `wp_mail_succeeded` action-hook.
*
* @param array $mail_data An array containing the email recipient(s), subject, message, headers, attachments, and embeds.
*
* @return void
*/
function wp_kama_mail_succeeded_action( $mail_data ){
// action...
}
- $mail_data(array)
- The email data as an array. Contains the subject, message, headers, and attachments.
Examples
#1 Data received by the hook
// Send an email $to = '[email protected]'; $subject = 'Message subject'; $message = 'Email content'; $headers = [ 'From: Me Myself <[email protected]>', 'content-type: text/html', 'cc: John Q Codex <[email protected]>', 'cc: John2 Codex <[email protected]>', 'bcc: [email protected]', ]; $attachments = []; wp_mail( $to, $subject, $message, $headers, $attachments );
See what data the hook receives:
add_action( 'wp_mail_succeeded', function ( $mail_data ) {
print_r( $mail_data );
} );
/*
Array
(
[to] => Array
(
[0] => [email protected]
)
[subject] => Message subject
[message] => Email content
[headers] => Array
(
)
[attachments] => Array
(
)
)
*/
As shown, headers is empty (it is cleared along the way).
Changelog
| Since 5.9.0 | Introduced. |
| Since 6.9.0 | The $embeds element was added to the $mail_data array. |
Where the hook is called
wp_mail_succeeded
wp-includes/pluggable.php 651
do_action( 'wp_mail_succeeded', $mail_data );