首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >wp_mail()在主域上不起作用,但在子域上起作用

wp_mail()在主域上不起作用,但在子域上起作用
EN

Stack Overflow用户
提问于 2016-04-13 14:13:49
回答 1查看 1.2K关注 0票数 1

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

代码语言:javascript
运行
复制
<?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文件,但问题仍然存在。

更新代码:

代码语言:javascript
运行
复制
<?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';

}
EN

回答 1

Stack Overflow用户

发布于 2019-09-04 05:21:40

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36590052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档