0

I have a multisites wordpress project in local (using docker), and I am using WP Mail SMTP plugin to handle sending emails.

I did configure the plugin with my mailtrap credentials, and everything is fine because I tested it and it worked, I received the email.

The problem is that when I use the wp_mail function I can't manage to send an email. After a long period of debugging I came across the error: Could not instantiate mail function, but I've searched and searched and I haven't found a solution.

Here is my code

$to = $email;
$subject = 'Welcome to our Website';
$message = 'Dear User, welcome to our website!';
  
$result = wp_mail($to, $subject, $message);

I hope someone have an idea about what's going on.

Yuu
  • 49
  • 8

1 Answers1

1

The error message "Could not instantiate mail function" is given by PhpMailer (via wp_mail()) when sending the email with PHPs mail() function returned false. (ref-1, ref-2 and ref-3)

Configure your PHP mail settings so that it uses your mailtrap and then you're ready to go. If your mailtrap supports PHP it should have documentation about how to configure it for PHP, too.

Alternatively, as you're using PHPMailer via wp_mail(), you can also configure it to use the SMTP settings. But this might be less straight forward as, if I understood that right from your question, you already did that via a plugin, but in the end were not able to. Nevertheless, the wp_mail() documentation covers that, too.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • As you said I already did configure it via plugin, and like I said when I run the test I receive the email in mailtrap. Are you saying there is another thing to configure so that I can use wp_mail? Maybe in wp-config.php? But I don't have any idea to be honest – Yuu Jul 14 '23 at 09:47