美好的一天,我在functions.php文件中写了一些代码,一旦所有发布的帖子都用关键字更新,它将把电子邮件发送给网站所有者。 (与数据库有关)。
global $wpdb;
// Calculate whether all posts are updated
$getToTalUnUpdatedPosts = $wpdb ->get_var(
"select count(*) from wp_posts where check_key = 0 and post_type = 'post' and post_status='publish'"
);
$getToTalUpdatedPosts = $wpdb ->get_var(
"select count(*) from wp_posts where check_key = 1 and post_type = 'post' and post_status='publish'"
);
// send email to inform once there's no posts left unupdated
if( $getToTalUnUpdatedPosts == 0){
$email = get_option("email_error_id") != "" ? get_option("email_error_id") : "myEmail@gmail.com";
var_dump($email); //get email of the receiver
$subject_mail = 'All posts with keywords updated completely';
$calculate_total_published_posts = $wpdb -> get_var(
"select count(*) from wp_posts where post_type= 'post' and post_status='publish' and post_content != ''"
);
$message_content = '<p> Total posts in your database : '. $calculate_total_published_posts . '</p>
<p> Total posts updated with keywords : ' .$getToTalUpdatedPosts. '</p> ';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
var_dump($headers);
$success = wp_mail($email, $subject_mail, $message_content , $headers);
var_dump($success);
}
但是,$success
的调试值始终返回false,我无法收到任何电子邮件。
我的网站也支持SMTP,但是此操作无法触发。