benecaster_email_headers
Filters the full headers array passed to wp_mail(). Common uses: add Reply-To for broadcasts, add X- tracking headers (SendGrid, Postmark, Mailgun), add CC/BCC for admin copies. Do not remove the List-Unsubscribe and List-Unsubscribe-Post headers that Benecaster adds to non-transactional emails — removing them risks emails being routed to spam. Those two are added only for non-transactional types with both a user and a show in context; transactional and admin-context mail carries neither, by design.
This filter fires at ENQUEUE time, not at send time, and the two are different PHP requests. wp_mail() is called later by the queue processor, on the benecaster_process_email_queue cron hook. Do not pair this filter with a mailer-side filter (wp_mail_smtp_providers_mailer_get_body, phpmailer_init, and the like) and expect to pass state between them in a static property or a global — nothing survives the boundary, and the failure is silent. Put everything you need into the headers themselves, which are carried through the queue.
A type-specific variant is available — append the email type to the hook name (e.g. benecaster_email_headers_welcome) to target a single type; the $email_type parameter is omitted on the type-specific variant.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$headers |
array |
— | Email headers array |
$email_type |
string |
— | Email type string |
$user_id |
int|null |
— | WordPress user ID; null for admin-only emails |
$show_id |
int|null |
— | ID of the show; null when not show-specific |
Returns:
array
Example
add_filter( 'benecaster_email_headers', function( $headers, $email_type, $user_id, $show_id ) {
// Add a Postmark message stream tag for broadcasts.
if ( 'broadcast' === $email_type ) {
$headers[] = 'X-PM-Message-Stream: broadcast';
}
// Add a Reply-To for all emails.
$headers[] = 'Reply-To: hello@mypodcast.com';
return $headers;
}, 10, 4 );
Need this built rather than just documented? See our services →