PHP Mailer: Could not instantiate mail function

I’m using PHP Mailer and for some reason I occasionally get Could not instantiate mail function after submitting the form.

I read up on it, and in class.phpmailer.php some people were saying to replace root@localhost with a valid email address on the server itself.

public $From = 'root@localhost';

I did that but it still gives me the same message sometimes (i.e. every 2nd or 3rd submission shows the error, otherwise it goes through without any hiccups.)

I’ve been trying to resolve this all day - any help is greatly appreciated.

Your code example suggests that you actually edited the class.phpmailer.php file rather than setting the variable from outside the class (like your suppose to)

$m = new PHPMailer;
$m->From = 'root@localhost';

This won’t cause or fix your issue though. If the issue is truly intermittent, then I would have to say it is something with your environment (os). Are you on shared hosting?

Thanks for the reply. I’m new to PHP Mailer. What do you mean by setting the variable outside the class?

I thought it should be edited directly in that file.

I gave you an example of what I meant. The PHPMailer class is meant to provide you the tools to procedurally do anything you need to do, without editing the original package files, just your own. Why don’t you share your relevant source code with us.