1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Handling Incoming Mail - MailServers

Discussion in 'PHP' started by T0PS3O, Aug 25, 2005.

  1. #1
    I need a solution like this one where my mailserver picks up certain e-mail accounts and forwards them to a script that rips them apart and performs certain functions based on the content.

    However, that tutorial's solution requires PHP being compiled as a CGI binary whereas mine is an Apache module.

    I contacted the author of the article and he confirmed there still no way around that. One alternative he mentioned is to have pop web email and use the script on those emails.

    My question is, have any of you worked with incoming email handling via PHP before? What are your experiences with it? And what about pop web mail on Apache module PHP? Any products you can refer me to?

    My servers come with Sendmail, PostFix and Qmail. Which one can you recommend looking into first?
     
    T0PS3O, Aug 25, 2005 IP
    SEbasic likes this.
  2. Gmorkster

    Gmorkster Peon

    Messages:
    202
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What you could do is have your mail servers forward all email to a certain address and write a script that queries that POP3 account regularly via a cron job. It's possible and quite straightforward if you have PHP imap_*() functions enabled.

    An issue I ran into is that a whole lot of web hosts, including popular ones like Pair, don't compile their PHP with --with-imap, since it could hang the httpd (which makes sense, as one thread could be used for minutes continuously if the remote host is not accessible or there's lots of email to be fetched).

    If PHP doesn't work, you can use a Perl script to fetch the email and dump everything into a text file or database, since Perl and the necessary modules are most likely present on your server. This solution is a bit sloppy but works in all server configurations.

    Let me know if you need further help.
     
    Gmorkster, Aug 27, 2005 IP
    T0PS3O likes this.
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Gmorkster. Didn't think of Perl as an alternative.

    Here's my relevant imap details form a phpinfo():

    Here's the scenario I want to tackle:

    A 3d party service provider send automatic e-mails based on certain events to do with the service. Based on the contents I want to do a db operation. The emails come in to so I need to set it up to take that one only and send it to a PHP script which will do the business.

    So you reckon I can set up a pop3 account and call imap functions with a cron job?

    I'm a novice to all that, would you know a place for me to read up on it all? Does it involve some scripts or modules ot be installed or is pop3 exactly what Qmail, Postfix and SendMail offer?
     
    T0PS3O, Aug 30, 2005 IP
  4. Gmorkster

    Gmorkster Peon

    Messages:
    202
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Looks like your server comes with everything you need to make it work. And yes, you can write a script that queries the POP3 account and performs specific operations based on the content and make it run every x minutes via a cron job.

    The script should be extremely straightforward, you need just a few lines of code for connecting and fetching the email. The PHP imap function reference you can find at http://php.net/imap -- also look at the examples and user comments that come with each function.

    I believe I've seen some classes on phpclasses.org that wrap around these functions, you might find one of those easier to use.

    Not quite sure what you mean by that-- you can set up the POP3 account with whatever your server comes with, no extra fuss.
     
    Gmorkster, Aug 30, 2005 IP
  5. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #5
    My server comes with Qmail, PostFix and SendMail. That last question of mine was whether them 3 mailserver whateveryouwannacallits are all I need to set up POP3 then?

    Thanks a bunch for clearing all this up btw, I'll study the imap funcitons and dig out my phpclasses.org login details to have a browse.
     
    T0PS3O, Aug 30, 2005 IP
  6. Gmorkster

    Gmorkster Peon

    Messages:
    202
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes.

    You're welcome :)
     
    Gmorkster, Aug 30, 2005 IP
  7. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Qmail claims to be the one most used world wide. Would you agree I'd focus my research on that one? I don't fancy playing around with all 3 to be honest, would rather elimate one or two right away.
     
    T0PS3O, Aug 30, 2005 IP
  8. Willy

    Willy Peon

    Messages:
    281
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Alas, though the rest of Gmorkster's advice was excellent, I have to contradict one point: MTAs (mail transport agents), such as the three mentioned applications, work with SMTP, and don't concern themselves at all with POP3, IMAP and so forth. (Qmail is almost an exception, since it's got a closely coupled POP3 daemon).

    Setting up POP3 or IMAP on a Unix server is an entirely different operation, and doesn't involve the MTA except to agree on a standard storage format (usually either mailbox or maildir, the latter being the more modern). What you need to do is install and configure a POP3 daemon in addition to the MTA; I recommend using Courier's POP3 daemon, since it comes standard on most Linux distros and supports the maildir storage format out of the box.

    As for the actual MTA, I've used all the different popular options over the years, and Exim would definitely be my number-one choice now. The second place goes to Postfix, which is excellent as well. Qmail is decent but somewhat quirky (but does have that tightly coupled POP3 daemon going for it...), and Sendmail I'd stay away from at all costs (you will too, after you've had a go at configuring it ;)).

    If you need any help setting all this up, drop me a PM ;)
     
    Willy, Aug 30, 2005 IP
    T0PS3O likes this.
  9. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Excellent advice Willy and I agree on all of it.

    I personally would go with a Courier/Qmail combination, but that is only because I know it so much better than the rest.
     
    blinxdk, Aug 30, 2005 IP
  10. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks Willy & Blinx!

    I found out a bit more about PHP's imap functionality and found some classes that wrap up all the functionality nicely. I'll check-out the mentioned POP3 packages.

    Thanks a bunch!
     
    T0PS3O, Aug 31, 2005 IP
  11. upshut

    upshut Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This seems like a thread that is more than 3 years old but i'm facing the exact same issue.
    I have PHP compiled as an Apache module, not a CGI binary. I'm running cygwin with exim. Exim works to send email. However, what I am trying to accomplish is Incoming PHP mail. I want to be able to send all incoming mail...abc@myserver.com to a script, which will then parse the email and store it in a database.

    I already went through the steps mentioned in the evolt incoming php mail tutorial (for my exim installation, but with no success.) I dont know how to proceed.

    If anyone knows how to do this, please let me know.
     
    upshut, Sep 11, 2007 IP
  12. email2php.com

    email2php.com Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Hello upshut,

    as I have just come across your message: Try consider our service at

    www.email2php.com

    It saves you the effort of puzzling about the correct server configuration. We transform every received email into a http request that calls one of your specified scripts, with the email content delivered in one request variable.

    Should be straightforward with this to get your things going.

    Thomas
    email2php.com
     
    email2php.com, Jan 14, 2008 IP