Bobcares

PHPMailer could not instantiate mail function – Why does this happen?

by | Nov 20, 2019

Are you stuck with “PHPMailer could not instantiate mail function”?

PHPMailer helps to send emails safely and easily from a web server. However, it often errors out due to misconfigurations of the mail() function, absence of local mail server and so on.

At Bobcares, we often receive requests to fix this error as part of our Server Management Services.

Today, let’s have a deep look at this error and see how our Support Engineers fix PHPMailer easily.

 

Why does PHPMailer could not instantiate mail function occurs?

As we all know, PHPMailer is a popular code for sending email from PHP. And, many open-source projects like WordPress, Drupal, etc use them.

PHPMailer validates email addresses automatically and protects against header injection attacks.

Developers often prefer sending mail from their code. And, mail() is the only PHP function that supports this.

But, sometimes the incorrect PHP installation fails to call the mail() function correctly. This will cause mail function errors.

Similarly, in some cases, the absence of a local mail server will also cause this error.

 

How to fix “PHPMailer could not instantiate mail function”?

So far we have discussed the error in detail. Now, let’s have a look at some of its top fixes.

There are alternative ways to resolve this error easily.

 

1. Using SMTP to send the email

As we have already said, if the PHP installation is not configured to call the mail() function correctly, it will cause the error.

So, in such cases, it is better to use isSMTP() and send the email directly using SMTP.

This is faster, safer and easier to debug than using mail(). This will resolve the error easily.

 

2. Install a local mail server

The PHP mail() function usually sends the mail via a local mail server.

So, using SMTP will not resolve the error if a mail server is not set up on the localhost.

Therefore, it is necessary to install a local mail server. For instance, we can install PostFix to the server using the below command.

sudo apt-get install postfix

 

3. Other Solutions

The PHP mail() function works with the Sendmail binary on Linux, BSD, and macOS platforms.

So, it is important to ensure that the sendmail_path points at the Sendmail binary, which is usually /usr/sbin/sendmail in php.ini.

Similarly, sometimes when we try to send large emails, it returns “Could not instantiate mail function” error along with  “Cannot send message: Too big” message in the PHP error log.

This means the mail transfer agent is refusing to deliver these emails.

So, we need to configure the MTA to allow larger attachments to resolve the error.

 

[Still facing difficulty to fix PHPMailer error?- We’ll help you.]

 

Conclusion

In short, PHPMailer could not instantiate mail function occurs due to misconfigurations of the mail() function, absence of local mail server and so on. In today’s writeup, we discussed this error in detail and saw some of the major fixes by our Support Engineers.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.