Header RSS Feed
 
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Joomla forms (PHPMailer) do not work with mini_sendmail
Tuesday - Jul 17th 2012 - by - (0 comments)

Joomla's contact forms use a third-party software called PHPMailer which can be found in libraries/phpmailer/phpmailer.php.
In most hosting environments this works fine, but on some special installations, namely servers which use mini_sendmail instead of sendmail, all contact forms (and other components which need to send e-mails) won't work.

The following error is shown when trying to send an e-mail with a contact form in Joomla (tested with 2.5.6):

Could not instantiate mail function. (in English)
Mail-Funktion konnte nicht initialisiert werden! (in German)

To debug it, it was necessary to use a standalone PHPMailer script (without Joomla). Fortunately, PHPMailer comes with some handy examples. In my case I re-used test_mail_basic.php.
But as soon as I launched test_mail_basic.php in the browser, this similar error message showed up (which is the same error message also shown in Joomla):

Mailer Error: Could not instantiate mail function.

After a lot of debugging I came across the params which are set in the file class.phpmailer.php:

  protected function MailSend($header, $body) {
    $toArr = array();
    foreach($this->to as $t) {
      $toArr[] = $this->AddrFormat($t);
    }
    $to = implode(', ', $toArr);

    if (empty($this->Sender)) {
      $params = "-oi ";
    } else {
      $params = sprintf("-oi -f %s", $this->Sender);
    }

And this is actually the big problem: The parameters (-oi / -oi -f) are added at the end of the @mail() command but this would only work if the sendmail binary (declared in php.ini under sendmail_path) is actually sendmail, and not anything else. mini_sendmail does not know how to handle these parameters and will therefore fail, causing PHPMailer to throw the "instantiate" error.

The following workaround allows to use PHPMailer with mini_sendmail. Just comment-out the $params definitions in the source code:

  protected function MailSend($header, $body) {
    $toArr = array();
    foreach($this->to as $t) {
      $toArr[] = $this->AddrFormat($t);
    }
    $to = implode(', ', $toArr);

    if (empty($this->Sender)) {
      //$params = "-oi ";
    } else {
      //$params = sprintf("-oi -f %s", $this->Sender);
    }

As soon as these lines were commented-out, the mail was sent and the following output confirmed it: Message sent!

As of the current version 2.5.6, Joomla is using PHPMailer in version 5.2.1. I'll report the bug and hopefully there will be a patch.
Once a patch has been released, I hope that the Joomla developers will then rapidly include the newer PHPMailer version in a new Joomla-release.

Update August 2nd 2012: The 'mini_sendmail bug' has been fixed in the current trunk version of phpmailer. I can confirm it's working. It's now up to the Joomla people to include a newer phpmailer version.

 

Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

7576 Days
until Death of Computers
Why?