Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple RSS to Email
<?php
$to = LIST_ADDRESS;
$from = SENDER;
$rss = 'http://chileoutreach.posterous.com/rss.xml';
$client = new Zend_Http_Client($rss);
$response = $client->request();
if(($status = $response->getStatus()) !== 200){
die("Got $status.");
}
$xml = new SimpleXMLElement($response->getBody());
$timstamp = time();
$db = Zend_Db::factory('Pdo_Sqlite', array('dbname' => 'rssmail.db'));
foreach($xml->channel->item as $entry){
$id = (string) $entry->guid;
$sql = "SELECT * FROM sent WHERE guid = ?;";
$res = $db->fetchAll($sql, $id);
if(count($res) > 0){
continue;
}
$subject = (string) $entry->title;
$body = (string) $entry->description;
$htmlBody = $body . HTML_INFO;
$textBody = preg_replace("/<.+?>/si", "", $body);
$textBody = TEXT_HEADER . $textBody;
$textBody .= TEXT_INFO;
$mail = new Zend_Mail;
$mail->addTo($to);
$mail->setFrom($from);
$mail->setSubject($subject);
$mail->setBodyHtml($htmlBody);
$mail->setBodyText($textBody);
$sql = "INSERT INTO sent (guid, timestamp) VALUES (?, ?);";
$res = $db->query($sql, array($id, $timstamp));
$mail->send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment