butlerblog
4/6/2015 - 7:44 PM

A quick-and-dirty plugin to filter the email from address and name

A quick-and-dirty plugin to filter the email from address and name

<?php
/*
Plugin Name: QnD wp_mail filter
Plugin URI:  http://butlerblog.com/
Description: A quick and dirty plugin to change the wp_mail "from" address to be something other than wordpress@mydomain.com.
Version:     1.2
Author:      Chad Butler
Author URI:  http://butlerblog.com/
License:     GPLv2
*/

/**
 * Set 'from' and 'name' values to your
 * email address and from name.
 */
function qnd_mail_settings() {
  $settings = array(
    'from' => 'myemail@mydomain.com',
    'name' => 'My Name',
  );
  return $settings;
}

/** no need to change anything else **/

/** Filter hooks. **/
add_filter( 'wp_mail_from',      'qnd_mail_from' );
add_filter( 'wp_mail_from_name', 'qnd_mail_from_name' );

/**
 * Filters the email address.
 */
function qnd_mail_from( $email ) {
	$settings = qnd_mail_settings();
	return $settings['from'];
}

/**
 * Filters the "from" name.
 */
function qnd_mail_from_name( $name ) {
	$settings = qnd_mail_settings();
	return $settings['name'];
}