Call to undefined function mime_content_type() in wp-mail.php line 163
galbaras opened this issue · comments
Some systems don't have the mime.magic module enabled, or are running versions of PHP without support for the function mime_content_type(). This results in the above fatal error.
The solution is rather simple. Please add this to your plugin:
if ( ! function_exists( 'mime_content_type' ) ) {
function mime_content_type( $filename ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mime_type = finfo_file( $finfo, $filename );
finfo_close( $finfo );
return $mime_type;
}
}
Sorry, it looks like the respective server doesn't like my code either. Any other ideas?
Me again. I've had to make the code check for "finfo_open" as well and use static defaults, but there are other solutions you may prefer. See the Notes section on http://php.net/manual/en/function.mime-content-type.php (I've gone with solution 23 by svogal)
@galbaras Can you tell me a little more about your WP configuration? Which version of WP, on what version of PHP / OS? I'd like to reproduce it if possible.
An easy fix would be for the plugin to rely on wp_check_filetype
WP 4.6.1, PHP 5.6, CentOS/cPanel/CloudLinux (not sure what version).
wp_check_filetype() looks like it's using similar code to what worked for me and seems like the way to go with the Postmark plugin.
@galbaras Well that's why WordPress has a lot of functions that seem to be reinventing the wheel but in reality are usually here to add better support for old or exotic systems.
@guillaumemolter you could argue that these can be improved or that the core team should require some minimum configuration and remove them. For the purpose of this issue, I think the solution is rather clear and clean. All that remains is for it to be done by the plugin developer(s), followed by our deep appreciation, of course ;>
@galbaras feel free to open a PR, that may speed up things.
I've already fixed the problem for me. This issue was opened as a public service and I don't know how to do a PR.
@galbaras Thanks for opening the Issue. This has been added to master, and will be in the next plugin release.