• I wanted to share this little piece of code with you.

    add_filter( 'option_mailer', 'childtheme_option_mailer' );
    function childtheme_option_mailer( $value ) {
    	if ( 'localhost' == $_SERVER['HTTP_HOST'] ) {
    		return 'smtp';
    	} else {
    		return 'mail';
    	}
    }

    change ‘localhost’ to whatever your host name is locally,

    this will override the option value set in the settings page, and it will send mails using mail() in your production server, and will use smtp when developing locally (comes in handy if you develop on windows)

    http://wordpress.org/extend/plugins/wp-mail-smtp/

Viewing 1 replies (of 1 total)
  • Interesting code. I’d think most people want SMTP used on their production servers and mail() on their local machines, but I can see your use case. I develop on a virtual machine, not localhost, but the same approach would apply I suppose.

    I like your approach of filtering option_mailer, that will likely trigger the other parts of the plugin to function correctly.

    Thanks for sharing. 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: WP Mail SMTP] Running mail in production server, and SMTP in localhost’ is closed to new replies.