I recently made a website for a local church. They wanted to be able to post new "blessings" to their web page, but didn't want to have to edit the web site or know any HTML. I asked if they knew how to send an email, and they said that this was a do able task.
Using a mail box on their server and a cron job I put in this script which gathers the "blessing" from the email box, and shooves it into a data base. From there the web page gets the informatin from the database (mysql in this case with a PHP page).
I' sure most of you do this type of thing all the time, but I thought it was such a cool little service to offer those who can't do more than send an email, a method of getting more out of their website and having a bit a fun at the same time.
Here's the script I used for the mail box. Any commet, as always, is welcome.
#! /usr/bin/perl -w
use strict;
use File::Spec;
use Mail::MboxParser;
use DBI;
my $dbh = DBI->connect('DBI:mysql:blessing:webadept.net',
'yourusername',
'yourpassword',
undef);
chdir("/var/spool/mail");
my $mail = File::Spec->catfile('blessing');
my $mb = Mail::MboxParser->new($mail);
my @a = $mb->get_messages;
my $mailbox = 'blessing';
open(IN,">$mailbox");
close(IN);
foreach my $msg(@a)
{<
my $subject = $msg->header->{subject};
my $from = $msg->header->{from};
my $body = $msg->body->as_string;
$body=$dbh->quote($body);
$from=$dbh->quote($from);
$subject = $dbh->quote($subject);
my $q = qq`insert into blessings values(
'',
$subject,
$body,
current_date,
$from,
1,
'')
`;
my $sth2 = $dbh->prepare($q);
$sth2->execute() || die "Failed on update : \n$q\n\n";
} #foreach message loop ends
$dbh->disconnect;
webadept
--if its not fun, its not worth it --
Edit kudra,
2002-02-26
Replaced BR with CODE
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.