• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

SOLVED - Could not instantiate mail function

nclaypool

Member
Perform a Github update to Fabrik this morning. Everything seems to be working except for one thing which worked prior to the update.

I have a form setup that sends emails whenever a record is saved or changed. When you submit the form you get the following error: Could not instantiate mail function

For testing purposes I sent a test message from the Global Configuration's mail settings and it worked fine. I also tried running one of the email scheduled tasks and it succeeded and the messages are received. So the problem is isolated to the Email Plugin on Forms.

As was mentioned in another article I switched from PHP mail to "Sendmail" doing so produced this error: Could not execute: /usr/sbin/sendmail -t -i but tests from Global Configuration were successful.
 
Some additional details.

For grins and giggles I grabbed the email.php file from plugins > fabrik_form > email from a backup I took this morning before the Github update and replaced the newer version on our server. Lo and behold the email plugin on the form I have started sending emails again. Since the old code lacks the check for missing files that caused failures to occur when no attachments were added to a record this will only be a temporary fix.

I tossed the two versions of the email.php file into Notepad++ and ran a comparison.
  • Aside from the aforementioned code I see a few lines where "return" was changed to "return true"
  • Line 138 "$message = ''; was removed in the new version
  • Reference to getting a new instance of JMail was removed in the new version
  • A reference to domPDF was slightly different, uses UTF decoding
That's it. The only thing I can think causing my issue is the loss of the "Jmail" reference line 336. I'm going to do some manual updating to this file to see if I can not only fix the attachment issue but keep email flowing. I'll post my results here.
 
Well I'll be damned. I got it fixed, not only the error but emailing attachments.

Here's what hand to change...
In the new email.php file the code was added to accommodate checking for a lack of attachments. A portion of that code appears to have replaced something in the original...this line in particular.
PHP:
$res = FabrikWorker::sendMail(
Compared to the line in the original
PHP:
$res = $mail->sendMail(

In addition this line was removed from the new version...
PHP:
mail = JFactory::getMailer();

By creating a hybrid of the two I was able to get it working. So my email.php for this section looks like this now.
PHP:
/*
                 * Sanity check for attachment files existing.  Could have base folder paths for things
                 * like file upload elements with no file.  As of J! 3.5.1, the J! mailer tosses an exception
                 * if files don't exist.  We catch that in the sendMail helper, but remove non-files here anyway
                 */

                foreach ($thisAttachments as $aKey => $attachFile)
                {
                    if (!JFile::exists($attachFile))
                    {
                        unset($thisAttachments[$aKey]);
                    }
                }


                // Get a JMail instance (have to get a new instance otherwise the recipients are appended to previously added recipients)
                $mail = JFactory::getMailer();
                $res = $mail->sendMail(
                    $emailFrom, $emailFromName, $email, $thisSubject, $thisMessage,
                    $htmlEmail, $cc, $bcc, $thisAttachments, $returnPath, $returnPathName
                );

I'll mark this thread as solved but I'd feel better if the Fabrik devs could inspect what I've changed to make sure I haven't introduced any security holes. Thank you!
 
Yup, looks like not everything got updated from github.

Suggest you do a full update again, and make sure EVERYTHING is uploaded, in "always overwrite" mode.

-- hugh
 
I did another update from Github, this time I used the methods outlined in your instructions under Cpanel as I figured that'd make it harder for human error to cause problems. I confirmed that the overwrite occurred based on the timestamp of the folders and files. But the mail function broke again until I replaced it with the hybrid file I made earlier.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top