The Error
The following error tends to appear when activating or updating a plugin from the WordPress plugin panel:
wp_mail has been declared by another plugin or theme
or, perhaps:
“Postman: wp_mail has been declared by another plugin or theme, so you won’t be able to use Postman until the conflict is resolved.
More info that may help – /path/to/home/wp-includes/pluggable.php:174”
Cause
While the error notification states “plugin or theme,” it is uncommon for the active WordPress theme to be the cause. In the following it is assumed that conflicting plugins are the root cause.
Somewhere, mostly likely in one of the activated plugins, the function wp_mail ()
has already been declared as a function, so it cannot be redeclared in a second plugin. Typically, the error will be thrown by the SMTP plugin in use on your site to process transactional emails (for example, form submissions, WordPress alerts, plugin notifications, etc.).
You may wish to review wp_mail () in the WordPress Developer Resources documentation.
Troubleshooting: Process of Elimination
As the error is mostly likely caused by a pair of conflicting plugins, the troubleshooting process is to systematically deactivate each plugin in the site until the conflicting pair of plugins can be isolated.
- Because troubleshooting involves deactivating plugins that may be crucial to the function of the site, it is best to conduct troubleshooting on a copy of your site moved to a staging or development server. If this is not possible consider undertaking testing during a period of low traffic or during off-hours and make sure to have a recent backup available.
- If you have a SMTP plugin installed, deactivate it and note if the conflict alert/error disappears. Typically, it is an SMTP plugin that will generate the error when another plugin is stopping it from functioning properly.
- If the error disappears, reactivate the SMTP plugin and start deactivating other plugins until the conflict alert disappears again.
- Continue deactivating the remaining plugins until only the SMTP plugin is active.
- Now reactivate the plugins, excluding the second plugin that appeared to trip the error. This will eliminate the possibility of a third plugin contributing to the error.
- Finally, reactivate the second plugin you identified as causing the error. The error should then reappear.
At this point, since the issue has been narrowed to two plugins, consider one of the following options:
- Consider temporary removal and replacement of the conflicting plugin.
- Communicate with the developers of both plugins to see if a fix is available.
Troubleshooting: Code Inspection
If process of elimination fails to isolate the conflicting plugin, you can attempt to inspect the code of the site’s various plugins.
Working from a backup of the site, you can use Visual Studio Code or similar tool capable of searching the code of all the files in the plugin directory (/wp-content/plugins).
Search for wp_mail
or wp_mail ()
.
You will likely find wp_mail
in many locations within the code of the installed plugins.
Those without wp_mail
can likely be removed from consideration as a possible cause.
The mere presence of wp_mail
in a plugin’s code does not necessarily mean it is the cause of the conflict. In most cases wp_mail
will be used properly. In order for a conflict to arise a function needs to be declared using wp_mail ()
, for example function wp_mail ()
. If you are capable of reviewing the related PHP code, look for that type of usage or something equivalent. Either way this approach will at least eliminate a number of installed plugins as a possible source of the issue.
Alternatives
If the error is being generated by an SMTP plugin, and you cannot locate the conflict or require the second plugin that is causing the conflict, you might try using a different SMTP plugin.
Some common options are:
Report Findings to the Plugin Developer
If you are able to isolate the cause of the conflict, be sure to report the issue to the developer of the conflicting plugin. If they are able to issue a patch, you save many others from a similar issue!
Thoughts?
I’d love to hear if you have solved this issue with another method. Drop me a comment below. Thanks!