Skip to content

Instantly share code, notes, and snippets.

@tjlytle
Created March 10, 2010 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjlytle/327869 to your computer and use it in GitHub Desktop.
Save tjlytle/327869 to your computer and use it in GitHub Desktop.
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