We use the plugin WP Mail From II to make all e-mails from the site appear to come from the site name and admin e-mail address rather than from "Wordpress."
However, the WP Mail From II plugin overrides the Contact Form 7 plugin - so that even Contact e-mails submitted from the Contact 7 forms on the site come to the Admins From the site name and e-mail, rather than from the sender. We want the Contact e-mails to come to the admins from the sender's name and sender's e-mail address, so that the admins can simply "Reply" to the sender.
I found this discussion thread on the Wordpress forum, which is exactly on point for this problem: http://wordpress.org/support/topic/p...contact-form-7.
I would like to implement the solution suggested at the end of this string -- however the php code change suggested in the WP Mail From plugin appears to relate to a previous version of that plugin.
Here specifically is the code change suggested in the "the last two functions in wp-mailfrom/wp-mailfrom.php":
Code:
function site_mail_from ($mail_from_email) { $site_mail_from_email = get_option('site_mail_from_email'); if( $mail_from_email != "wordpress@football-racing-betting-forum.co.uk" || empty($site_mail_from_email) ) { return $mail_from_email; } else { return $site_mail_from_email; } } function site_mail_from_name ($mail_from_name) { $site_mail_from_name = get_option('site_mail_from_name'); if( $mail_from_name != "WordPress" || empty($site_mail_from_name) ) { return $mail_from_name; } else { return $site_mail_from_name;
Can anyone help me revise the above suggested code so that it will work in the new version of the WP Mail From II plugin?
For reference, here in its entirety, is the new version of the WP Mail From II plugin's php file - wp-mailfrom-ii/wp-mailfrom-ii.php:
Code:
<?php /* Plugin Name: WP Mail From II Version: 1.0.1 Plugin URI: http://wordpress.org/extend/plugins/wp-mailfrom-ii/ Description: Allows you to configure the default email address and name used for emails sent by WordPress. Author: Ben Huson An updated and fully re-worked version of the WP Mail From plugin by Tristan Aston. http://wordpress.org/extend/plugins/wp-mailfrom/ Copyright (c) 2012, Released under the GPL license http://www.gnu.org/licenses/gpl.txt */ class WP_MailFrom_II { /** * Constructor */ function WP_MailFrom_II() { add_action( 'admin_init', array( $this, 'settings' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); // Name and email filter add_filter( 'wp_mail_from_name', array( $this, 'wp_mail_from_name' ), 1 ); add_filter( 'wp_mail_from', array( $this, 'wp_mail_from' ), 1 ); // Legacy support for old options - just in case someone used this directly! // (not really needed unless we can takeover the old plugin) //add_filter( 'pre_option_site_mail_from_name', 'get_option_site_mail_from_name', 1 ); //add_filter( 'pre_option_site_mail_from_email', 'get_option_site_mail_from_email', 1 ); } /** * Load Text Domain Language Support */ function load_textdomain() { load_plugin_textdomain( 'wp-mailfrom-ii', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); } /** * Filter: wp_mail_from_name * * @param string $name Default name. * @return string $name WP Mail From name. */ function wp_mail_from_name( $name ) { $wp_mailfrom_ii_name = get_option( 'wp_mailfrom_ii_name', '' ); if ( ! empty( $wp_mailfrom_ii_name ) ) { return $wp_mailfrom_ii_name; } return $name; } /** * Filter: wp_mail_from * * @param string $name Default email. * @return string $name WP Mail From email. */ function wp_mail_from( $email ) { $wp_mailfrom_ii_email = get_option( 'wp_mailfrom_ii_email', '' ); if ( ! empty( $wp_mailfrom_ii_email ) ) { return $wp_mailfrom_ii_email; } return $email; } /** * Admin Menu */ function admin_menu() { add_options_page( __( 'WP Mail From Plugin', 'wp-mailfrom-ii' ), __( 'Mail From', 'wp-mailfrom-ii' ), 'manage_options', 'wp_mailfrom', array( $this, 'settings_page' ) ); } /** * Settings Page */ function settings_page() { ?> <div class="wrap"> <div id="icon-options-general" class="icon32"><br></div> <h2><?php _e( 'Mail From Settings', 'wp-mailfrom-ii' ); ?></h2> <form action="options.php" method="post"> <?php settings_fields( 'wp_mailfrom_ii' ); do_settings_sections( 'wp_mailfrom_ii' ); ?> <p class="submit"><input name="submit" type="submit" class="button button-primary" value="<?php esc_attr_e( 'Save Changes', 'wp-mailfrom-ii' ); ?>" /></p> </form> </div> <?php } /** * Settings API */ function settings() { add_settings_section( 'wp_mailfrom_ii', '', array( $this, 'settings_section' ), 'wp_mailfrom_ii' ); add_settings_field( 'wp_mailfrom_ii_name', __( 'From Name', 'wp-mailfrom-ii' ), array( $this, 'wp_mailfrom_ii_name_field' ), 'wp_mailfrom_ii', 'wp_mailfrom_ii' ); add_settings_field( 'wp_mailfrom_ii_email', __( 'From Email Address', 'wp-mailfrom-ii' ), array( $this, 'wp_mailfrom_ii_email_field' ), 'wp_mailfrom_ii', 'wp_mailfrom_ii' ); register_setting( 'wp_mailfrom_ii', 'wp_mailfrom_ii_name', array( $this, 'sanitize_wp_mailfrom_ii_name' ) ); register_setting( 'wp_mailfrom_ii', 'wp_mailfrom_ii_email', 'is_email' ); } /** * Sanitize Mail From Name * Strips out all HTML, scripts... * * @param string $val Name. * @return string Sanitized name. */ function sanitize_wp_mailfrom_ii_name( $val ) { return wp_kses( $val, array() ); } /** * Mail From Settings Section */ function settings_section() { echo '<p>' . __( 'If set, these 2 options will override the name and email address in the <strong>From:</strong> header on all sent emails.', 'wp-mailfrom-ii' ) . '</p>'; } /** * Mail From Name Field */ function wp_mailfrom_ii_name_field() { echo '<input name="wp_mailfrom_ii_name" type="text" id="wp_mailfrom_ii_name" value="' . get_option( 'wp_mailfrom_ii_name', '' ) . '" class="regular-text" />'; } /** * Mail From Email Field */ function wp_mailfrom_ii_email_field() { echo '<input name="wp_mailfrom_ii_email" type="text" id="wp_mailfrom_ii_email" value="' . get_option( 'wp_mailfrom_ii_email', '' ) . '" class="regular-text" />'; } /** * Legacy support for get_option( 'site_mail_from_name' ) */ function get_option_site_mail_from_name( $option, $default = false ) { return get_option( 'wp_mailfrom_ii_name', $default ); } /** * Legacy support for get_option( 'site_mail_from_email' ) */ function get_option_site_mail_from_email( $option, $default = false ) { return get_option( 'wp_mailfrom_ii_email', $default ); } /** * Register Activation * Perform upgrades etc. */ function register_activation() { // Temporarily remove our filter which provide support for legacy options // (is only really needed if we can takeover the old plugin, but leave in for now) remove_filter( 'pre_option_site_mail_from_name', 'get_option_site_mail_from_name', 1 ); remove_filter( 'pre_option_site_mail_from_email', 'get_option_site_mail_from_email', 1 ); // Get old option value and try to assign them to new options $name = get_option( 'site_mail_from_name', '' ); $email = get_option( 'site_mail_from_email', '' ); $new_name = get_option( 'wp_mailfrom_ii_name', '' ); $new_email = get_option( 'wp_mailfrom_ii_email', '' ); if ( ! empty( $name ) && empty( $new_name ) ) $name_updated = add_option( 'wp_mailfrom_ii_name', $name ); if ( ! empty( $email ) && empty( $new_email ) ) $email_updated = add_option( 'wp_mailfrom_ii_email', $email ); // If new options created delete old options // (don't do this at the moment, only if we can takeover the old plugin) /* if ( $name_updated ) delete_option( 'site_mail_from_name' ); if ( $email_updated ) delete_option( 'site_mail_from_email' ); */ } } global $WP_MailFrom_II; $WP_MailFrom_II = new WP_MailFrom_II(); register_activation_hook( __FILE__, array( $WP_MailFrom_II, 'register_activation' ) );
Many thanks!