我在一台服务器上运行多个网站,由于某些原因,我似乎不能使用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';
}
发布于 2019-09-04 05:21:40
尝试更改电子邮件的标题。将表单属性添加或更改为子域,如"norepy@email.domain.com“而不是"noreply@domain.com”
https://stackoverflow.com/questions/36590052
复制相似问题