Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Marketplace » Customization, Design, Programming... »

WP Mail From II plugin breaks Contact Form 7


  #1  
Old Sep 19, 2013, 01:53 PM
New WordPress Fan
 
141 posts · Jul 2010
Using Wordpress 3.5.2 and Atahualpa 3.7.12

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;
The person suggesting this also said: "You will have to replace my website name (football-racing-betting-forum.co.uk) with your own in the above code snippet - or indeed spend five minutes making it work generically."

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' ) );
Specifically, what code changes would I make in the above php file of the new WP Mail From II plugin to make the same change that was suggested by the person in the forum above?

Many thanks!
  #2  
Old Sep 19, 2013, 02:55 PM
New WordPress Fan
 
141 posts · Jul 2010
Further to above:

I tried changing the function wp_mail_from_name($name) code in the above php file for the WP Mail From II plugin to read as follows:

Code:
function wp_mail_from_name($name) {
  $wp_mailfrom_ii_name = get_option('wp_mailfrom_ii_name',");
  if($name != "WordPress" || 
empty($wp_mailfrom_ii_name) ) {
    return $name;
  }
  else {
    return $wp_mailfrom_ii_name;
  }
And changed the function wp_mail_from($email) code to read as follows:

Code:
function wp_mail_from($email) {
  $wp_mailfrom_ii_email = get_option('wp_mailfrom_ii_email',");
  if($email != "wordpress@oursitename.com" || 
empty($wp_mailfrom_ii_email) ) {
    return $email;
  }
  else {
    return $wp_mailfrom_ii_email;
  }
However, after this change, I am getting the following error message in the plugin editor:

"This plugin has been deactivated because your changes resulted in a fatal error.
Parse error: syntax error, unexpected T_STRING in /home/content/25/3559525/html/HooDeeDo/wp-content/plugins/wp-mailfrom-ii/wp-mailfrom-ii.php on line 53"

Can anyone help correct whatever I have done wrong in the above changes?

Many thanks!

Last edited by New WordPress Fan; Sep 19, 2013 at 03:02 PM.

Bookmarks

Tags
contact form 7, plugins, wp mail from ii

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding e-mail contact link in footer JulianKaruk Post-Kicker, -Byline & -Footer 5 Apr 20, 2012 05:46 PM
Theme hacked via contact form 8? paulae Plugins & Atahualpa 2 Dec 20, 2009 03:12 PM
Customizing SimpleModal Contact Form (SMCF) - or can suggest a better plugin? kippiper Plugins & Atahualpa 0 Nov 29, 2009 01:32 PM
Contact Form 7 zizi Plugins & Atahualpa 2 Apr 15, 2009 09:53 AM


All times are GMT -6. The time now is 09:53 PM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.