默认值wp_mail()
函数是可插入的,这意味着它可以被插件完全覆盖。但是,在没有任何外部影响的情况下,电子邮件地址的“发件人”设置是硬编码的。
以下是/wp-includes/pluggable.php
:
// From email and name
// If we don\'t have a name from the input headers
if ( !isset( $from_name ) )
$from_name = \'WordPress\';
/* If we don\'t have an email from the input headers default to wordpress@$sitename
* Some hosts will block outgoing mail from this address if it doesn\'t exist but
* there\'s no easy alternative. Defaulting to admin_email might appear to be another
* option but some hosts may refuse to relay mail from an unknown domain. See
* http://trac.wordpress.org/ticket/5007.
*/
if ( !isset( $from_email ) ) {
// Get the site domain and get rid of www.
$sitename = strtolower( $_SERVER[\'SERVER_NAME\'] );
if ( substr( $sitename, 0, 4 ) == \'www.\' ) {
$sitename = substr( $sitename, 4 );
}
$from_email = \'wordpress@\' . $sitename;
}
// Plugin authors can override the potentially troublesome default
$phpmailer->From = apply_filters( \'wp_mail_from\' , $from_email );
$phpmailer->FromName = apply_filters( \'wp_mail_from_name\', $from_name );
我向您展示这个特定片段有两个原因:
它说明了如何设置发件人名称和电子邮件。默认情况下,邮件是使用以下地址从“WordPress”发送的[email protected]
... 无论什么sitename.url
可能是你的情况这表明你可以过滤一些东西如果你不想去plugin route, 您可以在主题或drop-in MU plugin.
add_filter( \'wp_mail_from\', \'wp44834_from\' );
function wp44834_from( $from_email ) {
return "[email protected]";
}
add_filter( \'wp_mail_from_name\', \'wp44834_from_name\' );
function wp44834_from_name( $from_name ) {
return "Bob";
}
这些过滤器将覆盖内置的默认设置,并使其看起来好像您的电子邮件实际上来自您而不是WordPress。