Wordpress:wp_mail()不在主域上工作,但在子域上工作

时间:2016-04-13 06:13:49

标签: php wordpress

我在一台服务器上运行多个网站,由于某种原因,我似乎无法使用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问题。

亲切的问候

更新: 所以我重新安装了我的核心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';

}

1 个答案:

答案 0 :(得分:0)

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