Oliver Spiesshofer wrote:
is there a script out there that can send RSS feeds to
a given email account?
It's a two-line affair, really:
$rss_feed = file_get_contents('http://example1.com/feed.rss');
mail('u***@example2.com', 'RSS Feed from Example1.com', $rss_feed,
'Content-Type: application/rss+xml');
yes but not exactly what I want.
I want each item of the rss sent as a seperate email with
the proper $from $subject etc fields filled in so I can mark
single items as read. Also, it should not send anything twice,
and check for new items in the rss feed at a given interval.
Ah, now we are talking specifications... First of all, "check
for new items in the rss feed at a given interval" cannot be
implemented in PHP; you'll have to use OS-level scheduling
facilities for that.
Given your preference for itemization, I don't think you'll be
able to find anything that will fit you out of the box. This,
however, should get you started:
$content = file_get_contents('http://example1.com/feed.rss');
$p = xml_parser_create();
xml_parse_into_struct($p, $content, $vals, $index);
xml_parser_free($p);
unset($content);
foreach ($index['LINK'] as $key => $link_id) {
$title_id = $index['TITLE'][$key];
$description_id = $index['DESCRIPTION'][$key];
$title = $vals[$title_id]['value'];
$link = $vals[$link_id]['value'];
$description = $vals[$description_id]['value'];
$subject = 'Example1.com: ' . $title;
$message = $title . "\r\n" . $link . "\r\n\r\n" .
wordwrap($description, 72, "\r\n");
mail('u***@example2.com', $subject, $message);
}
The only functionality missing from your request is "it should
not send anything twice". You can implement it by creating
a log file or a database where you will store URLs of pages
whose descriptions have already been sent. Let's say you
implemented these two functions:
boolean link_logged(string $link)
Returns true if $link is already in the database or false
otherwise.
void log_link(string $link)
Adds a new record to the log.
Then your code can morph into something like this:
$content = file_get_contents('http://example1.com/feed.rss');
$p = xml_parser_create();
xml_parse_into_struct($p, $content, $vals, $index);
xml_parser_free($p);
unset($content);
foreach ($index['LINK'] as $key => $link_id) {
$title_id = $index['TITLE'][$key];
$description_id = $index['DESCRIPTION'][$key];
$title = $vals[$title_id]['value'];
$link = $vals[$link_id]['value'];
$description = $vals[$description_id]['value'];
if (!link_logged($link)) {
$subject = 'Example1.com: ' . $title;
$message = $title . "\r\n" . $link . "\r\n\r\n" .
wordwrap($description, 72, "\r\n");
mail('u***@example2.com', $subject, $message);
log_link($link);
}
}
Proper "From:" heading is still missing, but it wouldn't be
too hard to add...
Cheers,
NC