Could not instantiate mail function. Why this error occurring

In Ubuntu (at least 12.04) it seems sendmail is not installed by default. You will have to install it using the command sudo apt-get install sendmail-bin

You may also need to configure the proper permissions for it as mentioned above.


I used this line of code

if($phpMailer->Send()){

    echo 'Sent.<br/>';

}else{

    echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>';

}

to find out what the problem was. Turns out, I was running in safe-mode, and in line 770 or something, a fifth argument, $params, was given to mail(), which is not supported when running in safe-mode. I simply commented it out, and voilá, it worked:

$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header/*, $params*/);

It's within the MailSend-function of PHPMailer.


I just had this problem and found in my apache error log that sendmail was'nt installed, after installation it was all working as it should!

root@web1:~$ tail /var/log/apache2/error.log
sh: 1: /usr/sbin/sendmail: not found

Had same problem. Just did a quick look up apache2 error.log file and it said exactly what was the problem:

> sh: /usr/sbin/sendmail: Permission denied

So, the solution was to give proper permissions for /usr/sbin/sendmail file (it wasn't accessible from php).

Command to do this would be:

> chmod 777 /usr/sbin/sendmail

be sure that it even exists!


Make sure that you also include smtp class which comes with phpmailer:

// for mailing
require("phpmailer/class.phpmailer.php");
require("phpmailer/class.smtp.php");