問題描述
如何將通知電子郵件地址從 WordPress @ mydomain.net 更改為其他內容。
我想這樣做是因為 WordPress @ mydomain.net 最終被標記為垃圾郵件。
謝謝
丹尼爾
最佳解決方案
我使用像 John P Bloch 和 Bainternet 這樣非常相似的方法,只是稍微有點靈活,所以我不必更改任何客戶端的郵件地址:
<?php # -*- coding: utf-8 -*-
/*
* Plugin Name: T5 Filter System From Mail
* Description: Sets the WP from mail address to the first admin』s mail and the from name to blog name.
* Plugin URI: http://toscho.de/?p=2201
* Version: 2012.08.30
* Author: Thomas Scholz
* Author URI: http://toscho.de
* 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' );
}
次佳解決方案
有一個偉大的外掛,這樣做你叫 Send From 。但是,如果你想自己滾動,那就很簡單了。要更改電子郵件地址,請在'wp_mail_from'
上新增一個過濾器,如下所示:
function just_use_my_email(){
return 'my.email@domain.com';
}
add_filter( 'wp_mail_from', 'just_use_my_email' );
您也可以使用'wp_mail_from_name'
過濾器更改發件人的姓名 (這是完全可選的):
function just_use_my_email_name(){
return 'My Real Name';
}
add_filter( 'wp_mail_from_name', 'just_use_my_email_name' );
只是交換真實的電子郵件地址的假值,你很好去。
第三種解決方案
這裡:
//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@Domain.com';
}
add_filter('wp_mail_from','my_wp_mail_from');
add_filter('wp_mail_from_name','my_wp_mail_from_name');
將名稱更改為您想要的名稱,並將 email@Domain.com 更改為您想要的電子郵件地址。但如果您更改電子郵件地址,那麼大多數反跨過濾器將阻止或垃圾郵件傳送給您的郵件進行欺騙。
第四種方案
現有的答案是一個更好的方式來做到這一點,不過還有一個我想提到的方法。
add_action('phpmailer_init','modify_phpmailer');
function modify_phpmailer($phpmailer) {
$phpmailer->From = "Full Name";
$phpmailer->FromName = "from@address.com";
$phpmailer->AddReplyTo("replyto@address.com");
}
這發生在* wp_mail_from *和* wp_mail_from_name *過濾器之後。因此,您可以強制更改,並防止其他外掛修改。您還可以直接與 phpmailer 物件進行工作,並執行諸如向地址新增回復 (如上所示)
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。