[Phpwm] Getting mail into a mysql database

Ian Munday ian.munday at illumen.co.uk
Fri May 29 09:04:02 UTC 2009


On 29 May 2009, at 07:54, Rob Allen wrote:

>
> 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...

I've implemented something very similar using Zend_Mail and a cron  
job, and it's proven to be very reliable.

I followed the example at http://webfractor.wordpress.com/2008/08/14/using-zend-framework-from-the-command-line/ 
  to get me up and running using Zend Framework from the command line.

The Zend Framework is my new favourite thing - it is really helping me  
bring together projects in a much more efficient, robust and  
structured way.  I previously had my own 'framework' (if one could  
call it that) which mirrored some of the structure, but the Zend  
Framework provides so much more functionality that I can utilise if /  
when required.  Do take a look if you haven't already - http://framework.zend.com/

Regards,

Ian





More information about the Phpwm mailing list