benecaster_email_send_failed
Fires when an email send failure is detected — specifically when wp_mail() returns false, indicating that the mail handoff to the local mail server or SMTP plugin failed. Use this hook for logging or alerting.
This hook does not cover delivery failures that occur after the handoff, such as bounces or spam filtering. For transactional delivery tracking beyond the handoff, use a dedicated SMTP service with webhook callbacks. The $subject parameter gives you the resolved subject line, which is useful for correlating log entries with specific email sends.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$email_type |
string |
— | Email type string |
$recipient |
string |
— | Recipient email address |
$subject |
string |
— | Resolved subject line |
$user_id |
int|null |
— | WordPress user ID of the recipient; null for admin emails |
$show_id |
int|null |
— | Show ID; null for emails not tied to a specific show |
Examples
Alert Slack on failed welcome email
add_action( 'benecaster_email_send_failed', function(
string $email_type,
string $recipient,
string $subject,
?int $user_id,
?int $show_id
): void {
if ( $email_type !== 'welcome' ) {
return;
}
wp_remote_post( MY_SLACK_WEBHOOK, [
'body' => json_encode([
'text' => sprintf(
':warning: Welcome email failed to send to %s (show %d).',
$recipient, $show_id
),
]),
'headers' => [ 'Content-Type' => 'application/json' ],
] );
}, 10, 5 );
Notes
This hook fires when wp_mail() returns false — it covers the handoff failure only, not downstream delivery failures such as bounces or spam filtering. For full delivery tracking, integrate a dedicated SMTP service that supports delivery webhooks.