Joomla forms (PHPMailer) do not work with mini_sendmail

Written by - 0 comments

Published on - Listed in Internet PHP Linux Mail


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.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder