首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cron不发送wp-mail()

Cron不发送wp-mail()
EN

WordPress Development用户
提问于 2019-04-26 09:05:52
回答 2查看 2.3K关注 0票数 1

我对cron调度函数有问题,它不想用wp_mail()函数发送电子邮件。

This是我的代码:

它放在functions.php中。

代码语言:javascript
复制
 5*60,
                'display' => __('Every Five Minutes'),
        );
        return $schedules;
    }

   if (!wp_get_schedule('send_review_invites_event')) {
       wp_schedule_event( time(), 'send_review_invites_interval', 'send_review_invites_event');
   }

   add_action( 'send_review_invites_event', 'send_review_invites' );

   function send_review_invites(){
       echo 'test';
       wp_mail( 'me@example.com', 'Automatic email', 'Automatic scheduled email from WordPress to test cron');
   }

?>

有些事情你应该知道,我已经把wp连接到我的服务器cron,所以它在我的网站上运行这个代码。我还将define('DISABLE_WP_CRON', false);放在wp-config.php中。

当服务器cron运行时,我在邮件中获得的输出会回显test。这显示了正在运行的函数send_review_invites()。然而,不知何故,我没有收到关于wp_mail()函数中给出的电子邮件地址的另一封邮件。

提前谢谢你的帮助。

EN

回答 2

WordPress Development用户

回答已采纳

发布于 2019-04-28 08:08:23

您可以使用以下方法测试邮件是否已发送:

代码语言:javascript
复制
// Set $to as the email you want to send the test to.
$to = "you@yoursite.com";

// Email subject and body text.
$subject = 'wp_mail function test';
$message = 'This is a test of the wp_mail function: wp_mail is working.woo!';
$headers = '';

// 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()所要求的。如果有疑问,也可以尝试使用SMTP来确认它。通过使用SMTP方法,如果它传递邮件,那么您的邮件服务器就会出现问题。

票数 0
EN

WordPress Development用户

发布于 2019-04-28 09:20:33

除了@Vishwa答案之外,您还可以根据以下链接记录wp_mail()函数:Wordpress参考

代码语言:javascript
复制
add_action('wp_mail_failed', 'log_mailer_errors', 10, 1);
function log_mailer_errors( $wp_error ){
  $fn = ABSPATH . '/mail.log'; // say you've got a mail.log file in your server root
  $fp = fopen($fn, 'a');
  fputs($fp, "Mailer Error: " . $wp_error->get_error_message() ."\n");
  fclose($fp);
}
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/336389

复制
相关文章

相似问题

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