WordPress的wp_mail无法将邮件发送到mailtrap。

huangapple go评论85阅读模式
英文:

WordPress wp_mail doesn't send emails to mailtrap

问题

我在本地使用多站点的WordPress项目(使用Docker),并且正在使用WP Mail SMTP插件来处理发送邮件。

我已经配置了插件使用我的Mailtrap凭据,一切都正常,因为我进行了测试,它可以正常工作,我收到了邮件。

问题是,当我使用wp_mail函数时,我无法成功发送邮件。经过长时间的调试,我遇到了错误:无法实例化邮件函数,但我已经搜索了很多次,没有找到解决方法。

以下是我的代码:

$to = $email;
$subject = '欢迎来到我们的网站';
$message = '亲爱的用户,欢迎来到我们的网站!';

$result = wp_mail($to, $subject, $message);

希望有人对发生了什么情况有想法。

英文:

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

得分: 1

错误消息"无法实例化邮件功能"由PhpMailer(通过wp_mail())在使用PHP的mail()函数发送电子邮件时返回false时给出。(ref-1ref-2ref-3)

配置您的PHP邮件设置,以便它使用您的mailtrap,然后您就可以开始使用了。如果您的mailtrap支持PHP,它应该有关于如何为PHP配置它的文档。

或者,由于您正在通过wp_mail()使用PHPMailer,您也可以配置它以使用SMTP设置。但这可能不太直接,因为如果我从您的问题中理解正确的话,您已经通过插件进行了配置,但最终无法成功。尽管如此,wp_mail()文档也涵盖了这方面的内容

英文:

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.

huangapple
  • 本文由 发表于 2023年7月14日 00:32:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定