Skip to content

Instantly share code, notes, and snippets.

@butlerblog
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save butlerblog/a2bf769b9befe7af55b3 to your computer and use it in GitHub Desktop.
Save butlerblog/a2bf769b9befe7af55b3 to your computer and use it in GitHub Desktop.
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'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment