更改WordPress邮件发送地址

Filter System From Mail

这段代码相当精简,作者将其做成了插件,名字就叫Filter System From Mail。代码如下

<?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:     1.1
Author:      Thomas Scholz
Author URI:  http://toscho.de
License:     GPL
*/
if ( ! function_exists( 'filter_system_from_mail' ) )
{
/**
* First admin's e-mail address or blog name depending on current filter.
*
* @return string
*/
function filter_system_from_mail()
{
return get_option( 'wp_mail_from' == current_filter()
? 'admin_email' : 'blogname' );
}
add_filter( 'wp_mail_from',      'filter_system_from_mail' );
add_filter( 'wp_mail_from_name', 'filter_system_from_mail' );
}
?>

将这段代码保存到一个文件里,上传到plugins目录下,到WP后台激活即可。

发送地址会变为:博客名称<管理员电子邮箱>

这样WordPress发送评论通知或者注册通知,from地址就是可控的了。

至于这段代码,写成插件可以,写到主题的functions.php中也行,用哪个是个人自由。很多人不喜欢用插件,觉得插件会降低性能,个人感觉差别不大,插件的移植性更好。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据