php - WP Mail SMTP 版本 1.4.2 停止发送电子邮件

标签 php wordpress smtp phpmailer

我有一个插件,它使用 wp_mail() 函数在表单错误时发送电子邮件。我还安装了 WP Mail SMTP 插件以使用我的自定义 SMTP 设置。

几个月来,WP Mail SMTP 0.11.1 版一切正常。但是自从我将插件更新到 1.4.2 版后,我的电子邮件就停止工作了。

据我所知,wp_mail() 不能仅在我的插件中运行。如果我将它保存在主题文件等任何地方,电子邮件将立即发送。但是从我的插件内部,我每次都会遇到这个异常:

  "errors": {
    "wp_mail_failed": [
      "Could not instantiate mail function."
    ]
  },
  "error_data": {
    "wp_mail_failed": {
      "to": [
        "oibrahim@folio3.com"
      ],
      "subject": "Form Error",
      "message": "<dl><dt>Error Logged:<\/dt> <dd>{\"MembershipNumber\":null,\"Success\":false,\"Message\":\"The combination is incorrect\",\"contactInfo\":{\"PrimaryContactNumber\":null,\"AlternateNumber\":null,\"MobileNumber\":null,\"OtherPhone1\":null,\"Email\":null},\"membership\":{\"EffectiveDate\":null,\"ExpiryDate\":null,\"planInfo\":null,\"MembershipSubProgram\":null},\"address\":{\"HomeAddress\":null,\"MailingAddress\":null,\"BillingAddress\":null},\"slxConstantInfo\":[],\"Token\":null}<\/dd><dt>Timestamp:<\/dt> <dd>Monday, April 22nd, 2019 @ 03:16:30 PM<\/dd><dt>Referrer:<\/dt> <dd>renew\/step1<\/dd><dt>User:<\/dt> <dd> \n<br>\n<br>\n<br>\n<\/dd><\/dl>",
      "headers": [

      ],
      "attachments": [

      ],
      "phpmailer_exception_code": 2
    }
  }
}

如果我降级 WP Mail SMTP 插件,一切都会重新开始正常工作。所以它肯定是插件的问题。也许在我调用 wp_mail() 函数的插件中,WP Mail SMTP 的设置尚未加载或类似内容。

任何快速帮助将不胜感激,因为我在生产站点上运行了这段代码。提前致谢!

编辑:只需添加一些细节,WP Mail SMTP 测试电子邮件运行良好!

最佳答案

没关系。我在 WP MAIL SMTP 支持论坛上发帖但没有得到回应。我发现 phpmailer 对象没有在我的插件中保存修改后的设置。所以这是我实现的解决方法,只是为了让事情正常进行,尽管我知道这不是最好的解决方法。

我在我的插件的 init 中放置了以下操作:

/**
 *  Reconfigure SMTP setting to make WP MAIL SMTP plugin work
 */
add_action( 'phpmailer_init', 'reconfigure_smtp' );
function reconfigure_smtp( $phpmailer ) {
    $SMTPhost = get_option('smtp_host');
    $SMTPport = get_option('smtp_port');
    $FromEmail = get_option('mail_from');
    $FromName = get_option('mail_from_name');
    $phpmailer->isSMTP();     
    $phpmailer->Host =$SMTPhost;
    $phpmailer->Port = $SMTPport;
    $phpmailer->From = $FromEmail;
    $phpmailer->FromName = $FromName;
}

这只是获取 WP MAIL SMTP 存储的选项,然后重新配置 phpmailer 实例。这只是迫切需要尽快解决问题的结果。

关于php - WP Mail SMTP 版本 1.4.2 停止发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55796717/

相关文章:

php - 如何在 CakePHP2 中缓存静态内容(css、图像、js 文件)?

javascript - TinyMCE:从模式窗口中的列表框中获取值

wordpress - 需要一个代码示例来展示如何使用 Codeigniter 发布到 Wordpress

smtp - exim 如何在日志文件中显示密码

PHPMailer - 某些 SMTP 消息不发送

PHP Resize图像给出黑色背景

php - 如何在php中恢复备份的mysql文件

php - ERD图设计问题

go - Golang:如何使用base64字符串作为附件内容发送带有图片的HTML正文电子邮件

css - 更改wordpress主题中元素的字体颜色