Customizing the email sender based on specific actions

Hi,

I need to customize the email addresses RentalHive uses to send notifications based on specific events. Currently, all communications are sent from a single email, but I want certain events, such as password reset, email verification, and user registration, to use a separate email address (support@…) to better manage communications and provide a better experience for users.

Not knowing if there is an easier option, I made this code for functions.php. But I don’t know if it works correctly.

function custom_email_from_for_specific_events( $email_data ) {
    $custom_slugs = array('user_password_request', 'user_email_verify', 'user_register');
    
    if ( isset($email_data['slug']) && in_array($email_data['slug'], $custom_slugs) ) {
        $email_data['from'] = 'support@yourdomain.com';
        $email_data['from_name'] = 'Support';
    }
    
    return $email_data;
}
add_filter( 'wp_mail', 'custom_email_from_for_specific_events' );

Thanks.

Hi,

I recommend using hivepress/v1/emails/email filter hook. Then, if you add a callback function for it, you can check the email subject, or use current_filter() function to get the current email hook and this way you can check which email is being sent, and set a “Reply-To” header for it in the headers array.

Hope this helps

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.