Change email sender address and name in WordPress – without plugin

How to change email sender address and name in WordPress without a plugin.

Change email sender address and name in WordPress without plugin

By default, WordPress sends emails with wordpress@yourdomain.com as sender address and WordPress as sender name. This can easily be changed by adding a few lines of code to your theme’s functions.php file.

To change sender (or “from”) address, add this:

function templ_custom_mail_from() {
    return 'harambe@mydomain.com';
}
add_filter('wp_mail_from', 'templ_custom_mail_from');

Just make sure to use a sender address with a domain name that you control and have configured for good email deliverability, otherwise emails that your site sends will almost certainly be marked as spam.

To change sender name, add this:

function templ_custom_mail_from_name() {
    return 'Harambe';
}
add_filter('wp_mail_from_name', 'templ_custom_mail_from_name');

Leave a Reply

Your email address will not be published.