最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to set custom from email address in wp

programmeradmin1浏览0评论

I want to set a custom from email address for emails that are sent via a plugin. I don't want to change default email address. The following code is not working:

add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');

function new_mail_from($old) {
 return 'your email address';
}
function new_mail_from_name($old) {
 return 'your name or your website';
}

I want to set a custom from email address for emails that are sent via a plugin. I don't want to change default email address. The following code is not working:

add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');

function new_mail_from($old) {
 return 'your email address';
}
function new_mail_from_name($old) {
 return 'your name or your website';
}
Share Improve this question edited Aug 1, 2019 at 11:29 butlerblog 5,1213 gold badges28 silver badges44 bronze badges asked Jul 30, 2019 at 7:53 Pranav PatelPranav Patel 211 gold badge1 silver badge4 bronze badges 3
  • This should work, except when the email you are trying to change are not sent using wp_mail(). – fuxia Commented Jul 30, 2019 at 9:39
  • yes I need that solution , the email which are not send using wp_mail() – Pranav Patel Commented Jul 30, 2019 at 9:44
  • 1 Then you can't. Fix the code to use wp_mail() instead. – fuxia Commented Jul 30, 2019 at 13:52
Add a comment  | 

1 Answer 1

Reset to default 0

Please use this below code for sending emails in wordpress, which will change the from name.

$recipient_email = "[email protected]";
$subject ="Submission";
$message = "I have done a submission"; 
$headers = 'Content-type: text/html;charset=utf-8' . "\r\n"; 
$headers .= 'From: Mastic Technology Rebate <[email protected]>' . "\r\n";
wp_mail($recipient_email, $subject, $message, $headers);
发布评论

评论列表(0)

  1. 暂无评论