From Name Replacement
-
I’m working on a plugin that sends out custom email notifications, and using the Easy WP SMTP plugin so I can use Amazon’s SES service for sending messages. I’m running into an issue though where my emails aren’t sending using the From Name as specified in the Easy WP SMTP settings. I did some digging and here’s what I’m finding:
Easy WP SMTP version 1.3.7
WordPress version 4.9.8Mock Email Implementation:
wp_mail([email protected], "Email Subject", "Message to be sent", array('Content-type: text/html'));
When I send out this email, it’s sending just fine, but it’s showing up using the From Name “WordPress” and the From Email address as specified in the Easy WP SMTP settings. I do not have the “Force From Name Replacement” checked.
From digging into the code I think I identified the problem. The wp_mail function in wp-includes/pluggable.php is defining the From Name on line 318 if it’s not defined in the headers. It’s not until line 477 of the same file where the phpmailer_init action is fired. If I’m understanding the code in the Easy WP SMTP plugin correctly, it’s hooking into the phpmailer_init action to fire the swpsmtp_init_smtp method in the easy-wp-smtp.php file of the plugin. On line 149 the plugin is looking to see if $phpmailer->FromName is empty, and if it is, it sets the From Name to the value from the plugin settings, otherwise, it uses the value already set, which in this case, WordPress has already defined the FromName, meaning that unless the “Force from Name Replacement” setting is checked, this will never be triggered.
I did run a test email in the Easy WP SMTP settings, however, the test message doesn’t use the built in wp_mail method to send the email, rather it’s instantiating it’s own instance of phpmailer to send the test message, so that doesn’t really do anything.
My proposed fix for this would be to add another conditional on line 149 to see if FromName is empty, or equal to “WordPress” and if either are true, proceed with the replacement.
Let me know if there’s something different I need to be doing. I know I could code in what the From Name should be, but this plugin I’m building can’t use a hardcoded value, so it would need to pull that value from somewhere, but can’t be guaranteed the Easy WP SMTP plugin will be in use on every site.
Hope I provided enough information to help.
David
- The topic ‘From Name Replacement’ is closed to new replies.