Setting a Custom Reply-To Email WordPress

A function to globally on a website change the reply-to email. Simple function to paste in your functions.php file.

I was trying to setup a reply to email globally on a website so I found this function that helped me achieve these.

function wp_mail_smtp_dev_reply_to( $args ) {
 
 $reply_to = 'Reply-To: Pattie Paloma <pattie@example.com>';
 
 if ( ! empty( $args['headers'] ) ) {
  if ( ! is_array( $args['headers'] ) ) {
   $args['headers'] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args['headers'] ) ) );
  }
 
  // Filter out all other Reply-To headers.
  $args['headers'] = array_filter( $args['headers'], function ( $header ) {
   return strpos( strtolower( $header ), 'reply-to' ) !== 0;
  } );
 } else {
  $args['headers'] = [];
 }
 
 $args['headers'][] = $reply_to;
 
 return $args;
}
 
add_filter( 'wp_mail', 'wp_mail_smtp_dev_reply_to', PHP_INT_MAX );