我对cron计划功能有问题,它不想用wp_mail()
作用
This is my code:
它被放置在函数中。php
<?php
add_filter(\'cron_schedules\', \'add_review_invites_schedule\');
function add_review_invites_schedule($schedules){
$schedules[\'send_review_invites_interval\'] = array(
\'interval\' => 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( \'[email protected]\', \'Automatic email\', \'Automatic scheduled email from WordPress to test cron\');
}
?>
您应该知道,我已将wp cron连接到服务器cron,因此它在我的网站上运行此代码。我还把
define(\'DISABLE_WP_CRON\', false);
在wp配置中。php。
服务器cron运行时,我在邮件中得到的输出test
. 这表明函数send_review_invites()
正在运行。但不知何故,我没有收到另一封电子邮件,地址是wp_mail()
作用
提前感谢您的帮助。
最合适的回答,由SO网友:Vishwa 整理而成
您可以使用以下选项测试邮件是否已发送:
// Set $to as the email you want to send the test to.
$to = "[email protected]";
// 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方法,如果它传递邮件,那么您的问题是邮件服务器。
SO网友:brobken
除了@Vishwa answer,您还可以记录wp_mail()
根据此链接的功能:Wordpress reference
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);
}