Wordpress wp_mail doesn't send emails to mailtrap

122 views Asked by At

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.

1

There are 1 answers

1
hakre On

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.