Created
March 10, 2010 13:38
-
-
Save tjlytle/327869 to your computer and use it in GitHub Desktop.
Simple RSS to Email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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