[Phpwm] Getting mail into a mysql database

Rob Allen rob at akrabat.com
Fri May 29 06:54:30 UTC 2009


On 28 May 2009, at 11:18, Mike Tipping wrote:

> I have a simple support system that allows people to submit messages  
> through
> a web form. These messages all go into a MySQL DB and are dealt with.
>
> I now want to add messages from email so all messages that come to a
> specific email address are parsed into the same DB.
>
> The mail server I'm using a the mo is Postfix.
>
> Any ideas on the best way of doing this.
>
> Cheers
>
> Mike
>

Last time I did this, I used Zend_Mail to read email via POP3 using a  
cron job. The core code looks like this:


$mail = new Zend_Mail_Storage_Pop3(array('host'     =>  
'mail.example.com',
                                          'user'     => 'username',
                                          'password' => 'pwd_here',
                                          'ssl'      => 'TLS'
                                          ));

echo $mail->countMessages() . " messages found\n";
foreach ($mail as $num=>$message) {
     echo "Mail from '{$message->from}': {$message->subject} - ";

     $subject = $message->subject;

     if (preg_match('@([\d]{5})@', $subject, $matches)) {
         $jobNumber = $matches[1];
         storeEmailMessage($jobNumber, $message);
         echo "Stored\n";
     } else {
         // no job number - discard
         echo "Discarded\n";
     }
     $mail->removeMessage($num);
}

Regards,

Rob...



More information about the Phpwm mailing list