$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>changing notification emails from WordPress <wordpress>@mydomain.net to something else|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

changing notification emails from WordPress <wordpress>@mydomain.net to something else

matteradmin10PV0评论

How do I change notification emails address from WordPress @mydomain to something else.

I want to do this because WordPress @mydomain ends up getting flagged as junk mail.

Thanks

Daniel

How do I change notification emails address from WordPress @mydomain to something else.

I want to do this because WordPress @mydomain ends up getting flagged as junk mail.

Thanks

Daniel

Share Improve this question edited Aug 27, 2011 at 14:26 Rarst 100k10 gold badges161 silver badges298 bronze badges asked Mar 18, 2011 at 12:21 user4030user4030 3
  • 1 Why not add the address to your safe senders list ? then it won't end up in the junk mail. – t31os Commented Mar 18, 2011 at 12:31
  • 1 That would work for me but not my users. – user4030 Commented Mar 19, 2011 at 2:54
  • That's fair enough, it wasn't clear that you weren't only referring to yourself in the opening question. – t31os Commented Mar 19, 2011 at 9:13
Add a comment  | 

4 Answers 4

Reset to default 23

I use a very similar approach like John P Bloch and Bainternet, just a little bit more flexible, so I don’t have to change the mail address for any client:

<?php # -*- coding: utf-8 -*-
/*
 * Plugin Name: Filter System From Mail
 * Description: Sets the WP from mail address to the first admin’s mail and the from name to blog name.
 * Version:     2012.08.30
 * Author:      Fuxia Scholz
 * Author URI:  https://fuxia.me
 * License:     MIT
 */

if ( ! function_exists( 't5_filter_system_from_mail' ) )
{
    /**
     * First admin's e-mail address or blog name depending on current filter.
     *
     * See wp-includes/pluggable.php::wp_mail()
     *
     * @param  $input Name or email address
     * @return string
     */
    function t5_filter_system_from_mail( $input )
    {
        // not the default address, probably a comment notification.
        if ( 0 !== stripos( $input, 'wordpress' ) )
            return $input; // Not auto-generated

        return get_option( 'wp_mail_from' === current_filter()
            ? 'admin_email' : 'blogname' );
    }

    add_filter( 'wp_mail_from',      't5_filter_system_from_mail' );
    add_filter( 'wp_mail_from_name', 't5_filter_system_from_mail' );
}

There's a great plugin that does this for you called Send From. However, if you want to roll this yourself, it's dead simple. To change the email address add a filter on 'wp_mail_from' like so:

function just_use_my_email(){
  return '[email protected]';
}

add_filter( 'wp_mail_from', 'just_use_my_email' );

And you can also change the sender's name using the 'wp_mail_from_name' filter like so (this is entirely optional):

function just_use_my_email_name(){
  return 'My Real Name';
}

add_filter( 'wp_mail_from_name', 'just_use_my_email_name' );

Just swap the fake values for your real email address and you're good to go.

here:

    //email from name function
function my_wp_mail_from_name($name) {
    return 'Name';
}

//email from email function
function my_wp_mail_from($content_type) {
  return '[email protected]';
}

add_filter('wp_mail_from','my_wp_mail_from');
add_filter('wp_mail_from_name','my_wp_mail_from_name');

Change Name to the name you want and [email protected] to the email address you want. but if you change the email address most anti span filter will block or spam your mail for spoofing.

The existing answers are a better way to do this, however there is an alternative I'd like to mention.

add_action('phpmailer_init','modify_phpmailer');

function modify_phpmailer($phpmailer) {

    $phpmailer->From = "Full Name";
    $phpmailer->FromName = "[email protected]";

    $phpmailer->AddReplyTo("[email protected]");
}

This happens after the *wp_mail_from* and *wp_mail_from_name* filters. So with this you can force a change and prevent other plugins from modifying it. You can also work directly with the phpmailer object and do things such as adding a reply to address (shown above)

Post a comment

comment list (0)

  1. No comments so far