Home / Admin / Emails via two different Postmark streams based on the email subject
Duplicate Snippet

Embed Snippet on Your Site

Emails via two different Postmark streams based on the email subject

WP Mail SMTP plugin does not directly support selecting a specific Postmark message stream based on the ‘From’ email address. This snippet allows conditional selection of the Postmark mailer message stream based on the email subject.

On line 9, you’ll need to replace WP Forms Subject with the subject of your email. Next, replacewp_forms_message_stream on line 10 with your desired Postmark message stream.

Code Preview
php
<?php
/* Emails via two different Postmark streams based on the email subject  
 * 
 * Original doc: https://wpmailsmtp.com/docs/how-to-set-up-the-postmark-mailer-in-wp-mail-smtp/
*/
// Conditionally set a Postmark mailer message stream in WP Mail SMTP
add_filter( 'wp_mail_smtp_providers_mailer_get_body', function ( $body, $mailer ) {
 
    if ( $mailer === 'postmark' && isset( $body[ 'Subject' ] ) && strpos( $body[ 'Subject' ], 'WP Forms Subject' ) !== false ) {
        $body[ 'MessageStream' ] = 'wp_forms_message_stream';
    }
    return $body;
}, 10, 2 );

Comments

Add a Comment