Cs cart ошибка could not instantiate mail function

Русскоязычный форум CS-Cart

Загрузка…

CS-Cart Forums

Loading

Our hosting team is continually working to ensure that the newsletters from your online store are always successful. To make it, we have implemented extra checks and improvements to get a high reputation for your domain and deliverability, which means your emails will be delivered and seen.

  • For example, sending emails to domains like test.com, example.org and similar ones are blocked. Don’t use domains like these for test purposes because you can’t check these email :)
  • We also check that an email can be delivered based on the DNS records, and if this check fails, it is also blocked email. This extra check helps us to fight against sending to domains where there are mistakes or mistyping, such as gmal.com (there's an omitted letter), hotmailcom (missed dot) and similar ones.

These types of errors can create message like shown below

Error-mail

Root causes¶

Sending emails to domains like test.com, example.org and similar ones

Don’t use domains like these for test purposes because you can’t check these email :) For test purposes we can recommend using the spam-check.glockapps.com, isnotspam.com, mail-tester.com, spamtest.smtp.bz and dkimvalidator.com or your real email address.

Sending emails to domains with mistakes or mistyping¶

Sometimes email can’t be delivered based on the DNS records (MX, A), and if this check fails, we blocked these sending attempts. This extra check helps us to fight against sending to domains where there are mistakes or mistyping, such as gmal.com(there’s an omitted letter), hotmailcom (missed dot), and similar ones.

Conclusion¶

Use valid email addresses and all will fine

  • How to: Mail Service for Ecommerce
  • Yandex.Mail – Free Complex Mailing Solution for Ecommerce Business

Hint

If you have a problem, need assistance with tweaks or a free consultation, if you just want to discuss your project with experts and estimate the outcome, if you’re looking for a solution that reinforces your online business, we will help. Let us know through MyCloud or email.

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»;

I’m using the mail() basic example modified slightly for my user id and I’m getting the error «Mailer Error: Could not instantiate mail function»

if I use the mail function —

mail($to, $subject, $message, $headers);

it works fine, though I’m having trouble sending HTML, which is why I’m trying PHPMailer.

this is the code:

<?php
require_once('../class.phpmailer.php');

    $mail             = new PHPMailer(); // defaults to using php "mail()"
    $body             = file_get_contents('contents.html');
    $body             = eregi_replace("[]",'',$body);
        print ($body ); // to verify that I got the html
    $mail->AddReplyTo("reply@example.com","my name");
    $mail->SetFrom('from@example.com', 'my name');
    $address = "to@example.com";
    $mail->AddAddress($address, "her name");
    $mail->Subject    = "PHPMailer Test Subject via mail(), basic";
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
    $mail->MsgHTML($body);
    $mail->AddAttachment("images/phpmailer.gif");      // attachment
    $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
?>

Stephen Ostermiller on Strike's user avatar

asked Aug 18, 2009 at 23:20

sdfor's user avatar

3

Try using SMTP to send email:-

$mail->IsSMTP();
$mail->Host = "smtp.example.com";

// optional
// used only when SMTP requires authentication  
$mail->SMTPAuth = true;
$mail->Username = 'smtp_username';
$mail->Password = 'smtp_password';

answered Aug 22, 2011 at 8:55

Mukesh Chapagain's user avatar

Mukesh ChapagainMukesh Chapagain

24.9k15 gold badges118 silver badges119 bronze badges

4

Your code looks good, did you forget to install PostFix on your server?

sudo apt-get install postfix

It worked for me ;)

Cheers

Andrew's user avatar

Andrew

18.4k12 gold badges103 silver badges117 bronze badges

answered Feb 6, 2018 at 13:22

Irwuin's user avatar

IrwuinIrwuin

5033 silver badges9 bronze badges

2

This worked for me

$mail->SetFrom("from@domain.co","my name", 0); //notice the third parameter

answered Feb 27, 2016 at 20:52

Matías Cánepa's user avatar

Matías CánepaMatías Cánepa

5,6934 gold badges57 silver badges96 bronze badges

2

$mail->AddAddress($address, "her name");

should be changed to

$mail->AddAddress($address);

This worked for my case..

answered Aug 31, 2011 at 12:09

Avinash's user avatar

AvinashAvinash

6,02415 gold badges60 silver badges95 bronze badges

5

You need to make sure that your from address is a valid email account setup on that server.

answered Jun 19, 2010 at 7:31

D.F.'s user avatar

D.F.D.F.

1851 silver badge6 bronze badges

0

If you are sending file attachments and your code works for small attachments but fails for large attachments:

If you get the error «Could not instantiate mail function» error when you try to send large emails and your PHP error log contains the message «Cannot send message: Too big» then your mail transfer agent (sendmail, postfix, exim, etc) is refusing to deliver these emails.

The solution is to configure the MTA to allow larger attachments. But this is not always possible. The alternate solution is to use SMTP. You will need access to a SMTP server (and login credentials if your SMTP server requires authentication):

$mail             = new PHPMailer();
$mail->IsSMTP();                           // telling the class to use SMTP
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.example.com";    // set the SMTP server
$mail->Port       = 26;                    // set the SMTP port
$mail->Username   = "johndoe@example.com"; // SMTP account username
$mail->Password   = "********";            // SMTP account password

PHPMailer defaults to using PHP mail() function which uses settings from php.ini which normally defaults to use sendmail (or something similar). In the above example we override the default behavior.

answered Aug 26, 2015 at 21:15

Salman A's user avatar

Salman ASalman A

261k82 gold badges429 silver badges521 bronze badges

The PHPMailer help docs on this specific error helped to get me on the right path.

What we found is that php.ini did not have the sendmail_path defined, so I added that with sendmail_path = /usr/sbin/sendmail -t -i;

answered May 4, 2017 at 1:24

Matt Pope's user avatar

Matt PopeMatt Pope

1672 silver badges11 bronze badges

1

In my case, it was the attachment size limit that causes the issue. Check and increase the size limit of mail worked for me.

answered Oct 31, 2018 at 17:59

fiskcn's user avatar

1

Seems in my case it was just SERVER REJECTION. Please check your mail server log / smtp connection accessibility.

answered Nov 10, 2016 at 10:32

Alex's user avatar

AlexAlex

1,2971 gold badge16 silver badges12 bronze badges

I had this issue, and after doing some debugging, and searching I realized that the SERVER (Godaddy) can have issues.

I recommend you contact your Web hosting Provider and talk to them about Quota Restrictions on the mail function (They do this to prevent people doing spam bots or mass emailing (spam) ).

They may be able to advise you of their limits, and if you’re exceeding them. You can also possibly upgrade limit by going to private server.

After talking with GoDaddy for 15 minutes the tech support was able to resolve this within 20 minutes.

This helped me out a lot, and I wanted to share it so if someone else comes across this they can try this method if all fails, or before they try anything else.

answered Jan 21, 2017 at 7:47

levi's user avatar

levilevi

1,5563 gold badges20 silver badges37 bronze badges

An old thread, but it may help someone like me. I resolved the issue by setting up SMTP server value to a legitimate value in PHP.ini

answered Jun 6, 2013 at 0:38

Atif.SQL's user avatar

I had this issue as well. My solution was to disable selinux. I tried allowing 2 different http settings in selinux (something like httpd_allow_email and http_can_connect) and that didn’t work, so I just disabled it completely and it started working.

answered Dec 30, 2014 at 19:53

iAndy's user avatar

iAndyiAndy

113 bronze badges

I was having this issue while sending files with regional characters in their names like: VęryRęgióńął file - name.pdf.

The solution was to clear filename before attaching it to the email.

answered Aug 20, 2016 at 19:20

jmarceli's user avatar

jmarcelijmarceli

19k6 gold badges69 silver badges67 bronze badges

Check if sendmail is enabled, mostly if your server is provided by another company.

answered Oct 5, 2017 at 13:43

Gianluca Demarinis's user avatar

For what it’s worth I had this issue and had to go into cPanel where I saw the error message

«Attention! Please register your email IDs used in non-smtp mails through cpanel plugin. Unregistered email IDs will not be allowed in non-smtp emails sent through scripts. Go to Mail section and find «Registered Mail IDs» plugin in paper_lantern theme.»

Registering the emails in cPanel (Register Mail IDs) and waiting 10 mins got mine to work.

Hope that helps someone.

answered Jun 21, 2018 at 10:19

MomasVII's user avatar

MomasVIIMomasVII

4,5314 gold badges34 silver badges49 bronze badges

A lot of people often overlook the best/right way to call phpmailer and to put these:

require_once('../class.phpmailer.php');

or, something like this from the composer installation:

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
require_once "../../vendor/autoload.php";

on TOP of the page before calling or including anything else. That causes the «Could not instantiate mail function»-error by most folks.

Best solution: put all mail handling in a different file to have it as clean as possible. And always use SMTP.
If that is not working, check your DNS if your allowed to send mail.

answered Dec 24, 2021 at 22:20

KJS's user avatar

KJSKJS

1,1761 gold badge13 silver badges29 bronze badges

My config: IIS + php7.4

I had the same issue as @Salman-A, where small attachments were emailed but large were causing the page to error out.
I have increased file and attachments limits in php.ini, but this has made no difference.

Then I found a configuration in IIS(6.0), and increased file limits in there.
iis config image

Also here is my mail.php:

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
require '../_PHPMailer-master/src/Exception.php';
require '../_PHPMailer-master/src/PHPMailer.php';

try{
    $email = new PHPMailer(true);
    $email->SetFrom('internal@example.com', 'optional name');
    $email->isHTML(true);
    $email->Subject   = 'my subject';
    $email->Body      = $emailContent;
    $email->AddAddress( $eml_to );
    $email->AddAttachment( $file_to_attach );
    $email->Send();
  }catch(phpmailerException $e){echo $e->errorMessage();}

future.

Stephen Ostermiller on Strike's user avatar

answered Sep 8, 2020 at 14:39

michal's user avatar

michalmichal

3274 silver badges15 bronze badges

We nee to change the values of ‘SMTP’ in php.ini file
php.ini file is located into

EasyPHP-DevServer-14.1VC11binariesphpphp_runningversionphp.ini

answered Oct 24, 2014 at 5:48

user3595601's user avatar

  • Crysis 3 exe ошибка приложения 0x0000906
  • Cs 2000 счетчик монет ошибки
  • Crysis 3 0xc0000906 ошибка win 10
  • Crystaldiskinfo частота ошибок чтения плохо
  • Crysis 2 произошла ошибка проверьте сетевое соединение