Could not instantiate mail function [OJS 3.3.0.11]

My OJS installation can’t send emails. The error log shows “Could not instantiate mail function”.

I’m running OJS 3.3.0.11, but this problem also occurred in OJS 3.3.0.10.

There were no problems for months, then this problem started to creep up intermittently. At first, the error occurred up to around 50% of the time, but now all email sending (e.g. “notify author”) fails with the error.

I’m not using SMTP (due to issues with the host).

The strange thing is, if I write a simple debug script using phpmailer (same version, 6.2.0), sending to the same addresses, and run the script on the same host, the email is sent fine!

Does anyone know how to fix it or how to troubleshoot further? Since I’m not using SMTP, I can’t seem to get OJS to return more detailed logs.

Just for info, this is the simple email sending debug script I used (addresses have been changed):

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require './Exception.php';
require './PHPMailer.php';

$mailer = new \PHPMailer\PHPMailer\PHPMailer(TRUE);

try {
	$mailer->IsHTML(true);
	$mailer->Encoding = 'base64';
	$mailer->XMailer = 'Public Knowledge Project Suite v3';
	$mailer->SetFrom('system@journal-name.org', 'OJS backend');
	$mailer->AddReplyTo('editor@journal-name.org', 'Editor');
	$mailer->AddAddress('author@university.edu', 'Author');
	$mailer->Subject = 'Test email';
	$mailer->Body = 'This is a <b>test email</b>';
	$mailer->AltBody = 'This is a test email';
	
	$mailer->Send();
} catch (Exception $e) {
	echo $e->errorMessage();
} catch (\Exception $e) {
	echo $e->getMessage();
}

?>

Hi @lktan

Are you running your debug script from the command line or a browser? The PHP mail functions might be disabled for CGI or PHP-FPM. If you look at the Administration area in your installation, there’s a way to get extended information about the PHP configuration of the server, which may tell you if mail is turned off, generally.

Best
Jason

Thanks for the reply.
I’m running the debug script from the browser (i.e., opening it through a regular link), so yeah, it should be going through the same server configuration as the OJS installation.

@lktan did you solved the problem? we are facing the same behavior

@Dr_Mohammad_Othman_N , sorry, we couldn’t figure out what was causing the issue. We eventually switched to using SMTP (the hosting service agreed to unblock it for us). SMTP has been working fine so far.