Wordpress:wp_mail()不适用于主域,但适用于子域


Wordpress: wp_mail() not working on main domain but works on sub domains

我在一台服务器上运行了几个网站,由于某种原因,我似乎无法使用wp_mail通过我的主域发送电子邮件。我创建的每个其他域和新域都工作,但不是主域。我试过使用包括wp-mail-smtp在内的几个插件,但不幸的是,我无法使用wp_mail函数让我的主域发送邮件。我可以使用mail()函数,但这并不理想,我听说它很容易被黑客入侵。我写了一个脚本来测试wp_mail函数:

<?php
/
**
 * This file can be used to validate that the WordPress wp_mail() function is working.
 * To use, change the email address in $to below, save, and upload to your WP root.
 * Then browse to the file in your browser.
 */
// Set $to as the email you want to send the test to
$to = "support@XXXXX.com.au";
// No need to make changes below this line
// Email subject and body text
$subject = 'wp_mail function test';
$message = 'This is a test of the wp_mail function: wp_mail is working';
$headers = 'no-reply@xxxx.com.au';
// Load WP components, no themes
define('WP_USE_THEMES', false);
require('wp-load.php');
// send test message using wp_mail function
$sent_message = wp_mail( $to, $subject, $message, $headers );
//display message based on the result.
if ( $sent_message ) {
    // the message was sent...
    echo 'The test message was sent. Check your email inbox.';
} else {
    // the message was not sent...
    echo 'The message was not sent!';
}

这个函数似乎可以用于我的子域,但不能用于我的主域。错误消息只是说消息未发送。有什么方法可以更好地测试wp_mail吗?也许能得到一条更有意义的错误消息,帮助我找出问题代码?我的主机提供商坚持认为这是一个文字压力问题。

向致以诚挚的问候

更新:所以我重新安装了我的核心wordpress文件,问题仍然存在。

更新代码:

<?php
/**
 * This file can be used to validate that the WordPress wp_mail() function is working.
 * To use, change the email address in $to below, save, and upload to your WP root.
 * Then browse to the file in your browser.
 */
// Set $to as the email you want to send the test to
$to = "support@xxxxx.com.au";
// No need to make changes below this line
// Email subject and body text
$subject = 'wp_mail function test';
$message = 'This is a test of the wp_mail function: wp_mail is working';
$headers = 'no-reply@xxxx.com.au';
// Load WP components, no themes
define('WP_USE_THEMES', false);
require('wp-load.php');
add_action('wp_mail_failed', 'print_r');
// send test message using wp_mail function
$sent_message = wp_mail( $to, $subject, $message, $headers );
//display message based on the result.
if ( $sent_message ) {
    // the message was sent...
    echo 'Message Sent';
} else {
    // the message was not sent...
     echo 'Message Not Sent';
}

尝试更改电子邮件的标题。将表单属性添加或更改为子域,如"norepy@email.domain.com"而不是"noreply@domain.com"

相关文章: