getMessage() ."\n");
}
$posts = "SELECT *
FROM blog_posts
WHERE
DAY(post_date) = '". date("j") ."'
AND MONTH(post_date) = '". date("n") ."'
AND YEAR(post_date) != '". date("Y") ."'
AND post_status = 'publish'
ORDER BY post_date ASC";
try {
$rows = $dbh->query($posts);
} catch (PDOException $e) {
die('Sorry, the query could not be executed. Error: '. $e->getMessage() ."\n");
}
if ($rows->fetchColumn() > 0) {
$body = "The following posts were published on the same day in the past:
\n\n";
foreach ($dbh->query($posts) AS $row) {
$body .= date("Y", strtotime($row['post_date'])) .": ". $row['post_title'] ."
\n";
}
# Mail results
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($mailto, 'Wordpress: blog post anniversaries! ('. count($rows) .')', $body, $headers);
}
?>