Skip to main content

benecaster_send_test_email()

Utilities Free
benecaster_send_test_email( string $type, string $to, array $context = [], ?int $show_id = null ): int

Sends a test of an email type to any address, with simulated data: what a “Send me a test” button does. It renders exactly as benecaster_render_email_preview() does, then queues the result to the address you give.

Parameters

Name Type Default Required Description
type string — Yes A registered email type slug.
to string — Yes The address to send the test to. It need not belong to an account.
context array [] No Tag values to use instead of the samples, keyed by tag name.
show_id int|null null No The show whose branding and show details to use, or null for an email with no show.

Return Value

Type: int

The email queue row ID, or 0 when the address is not valid, the type is empty or renders nothing, or the test could not be queued.

Example

$queue_id = benecaster_send_test_email(
    'welcome',
    wp_get_current_user()->user_email,
    [],
    $show_id
);
if ( 0 === $queue_id ) {
    // Not a valid address, or nothing to send.
}

Notes

A test is not a send of that type. It skips the opt-out check, because it goes to whoever asked for it. benecaster_before_email_send and benecaster_after_email_send do not fire, so nothing that reacts to a real welcome or receipt reacts to a test, and the email log records it as test. The benecaster_test_email_queued action fires instead.

The subject is the type's own. To put "[Test]" in front of it, add it through benecaster_email_subject.

It is queued like any email, so it arrives when the queue next runs, not instantly. Say so beside your button.

There is no capability check. Check manage_options, or your own capability, on the route that calls it.

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