From 124a12dfe0150d41c07ab89b26af6023be7f4744 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 23 Aug 2010 20:19:40 +0300 Subject: [PATCH] Releasing xkcd-mailer to the world --- README | 10 ++++++++++ xkcd-mailer.php | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 README create mode 100644 xkcd-mailer.php diff --git a/README b/README new file mode 100644 index 0000000..0a2c5c0 --- /dev/null +++ b/README @@ -0,0 +1,10 @@ +# xkcd-Mailer # + +Takes the first/latest item from the xkcd atom-feed and mails the image and punchline to a specified email address. + +## crontab example ## + +5 minutes over 7am on monday, wednesday and friday. + + 5 7 * * 1,3,5 /usr/bin/php /home/users/viir/code/php/xkcd-mailer.php + diff --git a/xkcd-mailer.php b/xkcd-mailer.php new file mode 100644 index 0000000..7c18f18 --- /dev/null +++ b/xkcd-mailer.php @@ -0,0 +1,41 @@ +"; + + $feed = "http://xkcd.com/atom.xml"; + $data = simplexml_load_file($feed); + $item = $data->entry[0]; + $date = date("Y-m-d", strtotime($item->updated)); + preg_match("#title=\"(.+)\"#iU", $item->summary, $t); + + // To send HTML mail, the Content-type header must be set + $headers = 'MIME-Version: 1.0' . "\r\n"; + $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; + $headers .= 'From: '. $from . "\r\n"; + + $subject = "xkcd {$date}: {$item->title}"; + $punchline = $t[1]; + + $msg = "

id}\">{$item->title}

\n" + . "Posted {$date}
\n" + . $item->summary."
\n" + . "

{$punchline}

\n"; + + mail($mail, $subject, $msg, $headers); \ No newline at end of file