procmail
[Top] [All Lists]

Re: Email to mySQL

2000-10-26 15:21:33

Wow, I see messages like this all the time.  Is there something I'm
missing?  Why are you putting your emails in a database?

Here's what I might start with (untested, of course!).  You're using
php4, right?

:0hb
| php -f /path/to/script.php

script.php
<?php
# load stdin in as one big string
$file = join('', file('php://stdin'));

# separate the header from the body
list($header,$body) = explode('\n\n', $file, 2);

$lines = explode('\n', $header);

# iterate through header looking for certain
$wanted_headers = array( 'sender', 'date', 'time', 'subject' );
while ($line = array_shift($lines))
  if (eregi('^$wanted_headers', $line))
    $$wanted_headers = eregi_replace('^$wanted_headers: ', '', $line);

# open up mysql
mysql_connect("localhost", "www", "www") 
  or die("Unable to connect to SQL server");
@mysql_select_db('maildb') 
  or die("Unable to select database $dbname");

# add your data
$query = <<<END
  insert into maildb
  set
    sender='$sender',
    date='$date',
    time='$time',
    subject='$subject',
    body='$body'
END

mysql_query($query)
  or die("$query didn't work!");
?>


On Thu, 26 Oct 2000, S K Rana wrote:



I need to break incoming emails on one e-mail address (say 
xyz(_at_)akr(_dot_)com)
in a format (sender, date, time, subject, body) to update in 
mySQL (DatabaseName: mailbase, TableName: xyz). I know a bit PHP to handle
further processing.

Can someone suggest complete script or directions?

Thanks.

S K Rana






_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>