Attention!
While searching for a solution I have found that the hosting service blocked mails, I'm not sure this is a valid question anymore, don't reply untile further notice.
The issue
Quoting from an old question of mine:
Well, not anymore. - and I have not touched anything:
- Last time I touchedmade any changes to the site (including Joomla updates) was in December.
- The last changes to the mailer (which isTo my knowledge, Joomla! uses PHPmailer, right?) were inwhose last changelog entry is from November.
- The PHP file was still working properly 7 days ago (02/02/2022).
- The PHP file returns a "Failed to start application" message since yesterday (and it does not sendwas first reported giving an error on 07/02/2022.
- My IT manager didn't recently introduce any firewall rules that might block e-mail)mails from my site.
I think this means that the try/catch structure of the PHP caught an exception with that name.
I have no idea why this happens and, after having scoured the forums for the large part of this working day, it's time to ask someone more knowledgeable.
Testing and debugging
After some testing, I have checkedam positive that the ajax call's payload in Chrome's DevToolscall works properly (Network > request > Payloadit outputs the expected payload) and it's still passingthat the correctPHP receives it (I have temporarily modified the PHP to echo the querystring instead of trying to my PHP mailersend the e-mail and it does so correctly).
This makes me think theThe problem is with, therefore, lies somewhere in the PHP. Here it is (anonymized to protect my Company)php file:
//_JEXEC must be 1 or require_once requests will fail because of their "_JEXEC or die"
define('_JEXEC', 1);
//Then #I Neededneed forto therequire 'require_once'some callsJoomla! below.files where getMailer is defined
define('JPATH_BASE', __DIR__);
require_once (JPATH_BASE.'/includes/defines.php');
require_once ('includes/framework.php');
try {
//fetching variables from querystring
$name=$_POST['name'];
$body=$_POST['body'];
$from=$_POST['from'];
//invoke mailer
$mail = \Joomla\CMS\Factory::getMailer(); # Invoke JMail Class
$mail->setSender('[email protected]');
$mail->addRecipient('[email protected]');
$mail->setFrom($from,$name); # who is it?
$mail->addReplyTo($from,$name); # who do I reply to?
$mail->setSubject('E-mail from Firefighter\'s form');
$mail->setBody($body);
$mail->ClearCCs();
$mail->ClearBCCs();
$mail->ClearAttachments();
$mail->ClearCustomHeaders();
$mail->Send();
echo "Mail sent";
exit;
}
catch (Exception $e) {
echo $e->getMessage();
}
It happened to meNo matter the input (which is validated and encoded with encodeURIcomponent in the past thatjs), the mailer changed syntaxtry/catch structure catches the "Failed to start application" exception.
Commenting out $mail->Send();
and it broke my codenothing else echoes "Mail sent", but as I mentioned there's not been an update inexpected (of course, the last few weeks somail is not sent)
I don't think this means that the mailer is instantiated correctly, or it would give some exception as soon as I try adding a recipient, instead it only fails way later.
Note: from now on, echo results with this line commented out will be labeled "try echo" and echo results with the line causing an exception will be labeled "catch echo".
Following suggestions by mickmackusa (who linked me some resources in the reasoncomments) I tried debugging by adding the following just before the try/catch structure...
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
My IT manager didn't recently introduce any firewall rules that might block e-mails from my site...and by echoing !$mail->isError();
in both the try and the catch, which gives me the following results:
- Try echo = 1
- Catch echo = nothing
Adding $mail->isHtml(true);
changes nothing at all.
Adding $mail->SMTPDebug = 2;
(or 3) gives the following results:
- Catch echo = Could not istantiate mail function.
It looks like the PHP installation is not configured to call the mail()
function correctly.
I have tried seeing if other people in forums had my same problems but all I found was the idea to check the mail sending parameters in Joomla!'s Global Configuration page.
E-mail sending: yes
Disable user e-mail sending: no
Email from: example.exampleexample@example.com
Sender name: Firefighter's company's page
Reply to e-mail:
Reply to name:
E-mail function: PHP mail
Anyway, The same as SMTPDebug.
###The question
howHow do I make my mailer work again?
(Of course, requests for more informations or instructions on how to gather more specific information on the error are welcome, as long as I don't need to disclose details about my company.)