Skip to main content

benecaster_after_email_send

Action Free

Fires after a Benecaster email has been queued, not after it is delivered. The message has been written to the email queue; Benecaster’s queue processor hands it to wp_mail() later, in a cron request, where it can still fail or be retried. $queue_id is the queue row, so you can follow the message: Benecaster’s own email log records it as queued here and moves it to sent or failed when the processor runs.

It does not fire for a send that benecaster_email_should_send refused — that fires benecaster_email_suppressed instead — or for one whose enqueue threw, which fires benecaster_email_send_failed. A test send fires benecaster_test_email_queued in its place.

Use this hook for logging, analytics tracking, or post-send side effects that should run after every email regardless of type. A type-specific variant is available — append the email type to the hook name (e.g. benecaster_after_email_send_welcome) to target a single email type; the $email_type parameter is omitted on the type-specific variant. The type-specific variant fires automatically for custom email types — no extra wiring is needed. Stable built-in type strings are listed on the benecaster_after_email_send_{type} reference page.

Parameters

Name Type Default Description
$email_type string — Email type string
$recipient string — Recipient email address
$subject string — Resolved subject line
$body_html string — Rendered HTML body
$body_text string — Rendered plain-text body
$headers array — Headers passed to wp_mail()
$user_id int|null — WordPress user ID, or null
$show_id int|null — Show ID, or null
$queue_id int — The email queue row id. Register the callback with 9 accepted arguments to receive it.

Examples

Track queued emails in analytics

// Fires once the email is queued. A refused send fires benecaster_email_suppressed
// and a failed enqueue benecaster_email_send_failed instead, so nothing here needs a flag.
add_action( 'benecaster_after_email_send', function(
    string $email_type,
    string $recipient,
    string $subject,
    string $body_html,
    string $body_text,
    array  $headers,
    ?int   $user_id,
    ?int   $show_id,
    int    $queue_id
): void {
    my_analytics_client()->track( 'email_queued', [
        'type'     => $email_type,
        'show_id'  => $show_id,
        'queue_id' => $queue_id,
    ] );
}, 10, 9 );

Type-specific variant for welcome emails

// Fires only for welcome emails — $email_type is omitted, so $queue_id is 8th.
add_action( 'benecaster_after_email_send_welcome', function(
    string $recipient,
    string $subject,
    string $body_html,
    string $body_text,
    array  $headers,
    ?int   $user_id,
    ?int   $show_id,
    int    $queue_id
): void {
    // ...
}, 10, 8 );

Need this built rather than just documented? See our services →