WordPress has wp_mail() function for sending emails via php code. By default, the default WordPress email address looks like WordPress@yoursitename.com. Want to use your real email and username instead? Just use the following code.
This code is pretty easy to implement: Just open your function.php file paste the following code:
function res_fromemail($email) { $wpfrom = get_option('admin_email'); return $wpfrom; } function res_fromname($email){ $wpfrom = get_option('blogname'); return $wpfrom; } add_filter('wp_mail_from', 'res_fromemail'); add_filter('wp_mail_from_name', 'res_fromname');
How to change WordPress’s default email address and site name
While messing around on a website built in WordPress, I noticed that whenever your WordPress installation emails you, the email address is of the type wordpress@yourdomain.com (in my example it would be wordpress@constantinosorphanides.com) and the sender’s name would be set to “WordPress”.
This was quite annoying and I could not find any straightforward solutions to replacing the default email address (and name) with the ones I wanted. Fortunately, there’s a simple way of changing this:
- Go to your WordPress administration panel
- Select Appearance > Editor
- On the right hand side of your screen you’ll see a column of WordPress files. Locate
functions.php
and open it. - At the end of the file, copy and paste the following code, replacing
your@email.com
andYour Name or Your Website
with the ones you want. - Press Save and you’re done.
add_filter('wp_mail_from_name', 'new_mail_from_name'); function new_mail_from($old) { return 'your@email.com'; } function new_mail_from_name($old) { return 'Your Name or Your Website; }
If your theme supports custom.php
and you decide to use it, make sure that the code above is accompanied by PHP’s opening and closing tags, as such:
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.com'; } function new_mail_from_name($old) { return 'Your Name or Your Website'; }