Ok..... basically what I'm trying to do is setup something that will handle all incoming mail on a certain POP3 email address, pass all the relevant data to a PHP script, which will then parse the data & insert it into a MySQL database.
Now I have been looking around a bit..... checked out procmail, but that just confused the hell outta me (I'm not much of a server guy, just know enough CL stuff to get by), so was wondering if there were any better options available to me or any existing PHP classes that made it a bit easier?
Thanks a lot - any help would be much appreciated!
Sounds like you have two tasks before you:
Write a PHP script that checks the POP3 account, processing any mail it finds.--You could use PHP's IMAP functionality, which supports IMAP, POP3 and NNTP.
Somehow get the above-mentioned script to run when new mail is received.--An easy way to simulate this effect would be to use a cron task to run your script regularly...perhaps every few minutes. Hopefully, your web host supports cron tasks--you may find an option to set them up in your hosting account's control panel or you may need to contact support for assistance.
Hope this helps,
Ben
There are some classes built to help you out as well:
http://www.phpclasses.org/package/2-PHP-Access-to-e-mail-mailboxes-using-the-POP3-protocol.html
As weird as it may sound, check out the imap extension of PHP. It supports POP3 and is fairly easy to use.
Related
Basically I've been asked if there is any way that I can capture & download all incoming and outgoing emails ( preferably in text format ) going through a mail server. This downloading method needs to be done using PHP or similar server side language.
If I can pass the above stage, then the final goal is easily reachable, which is to allow me process the emails via a script of some sort.
If there is any sort of mediating RPM I can install that would allow me to port emails to a directory somewhere, could also be of great help.
I am completely lost on where to start with this, so any sort of pointers or advice is greatly appreciated.
Thanks
Scott
More Info :
Server : CentOS
Mail Server : Pop3
"Downloading" email is the same is fetching email. Have a look at the PHP IMAP extension.
Plenty of examples there to get you going.
I am about to start a project that requires an email to be somehow ran through a PHP script. I have full control of the server that the email will be sent to and wondered if people could give me some thoughts or pointers as to the most elegant way parsing it with PHP. I am not editing the email and then forwarding it on.
The server is CentOS with Exim email.
Thanks in advance.
You implement a client for the mail box (php imap modules can work with pop3, imap4 and local mailboxes). You poll the mailbox for new arrived messages, retrieve new ones and parse it. All using the php imap module.
One of the best examples of this comes with Wordpress... there is a file wp-mail.php which is set up as a cron task to retrieve and parse emails... I have hacked it up several times to do such things!
To make life easier for you, rather that stress yourself with parsing emails (if you don't mind the cost) you could decide to use Postmark
I've been using their services for quite some time and i love them. They have an Incoming email API service now. Enough talk, simply check it out because I believe it will help with what you're trying to do.
There are three main approaches to this:
Run a cron task to poll an IMAP/Pop3 server every x minutes
Make exim run a script whenever it receives an email
Use a third party service to receive the email and send it on to your site.
I wrote a Blog Post detailing the options, although it's for Rails the main concept applies to any language including PHP.
I need in some way to accept incoming emails to my web application and save them in the database. My web application is written in PHP language and im using MySQL database.
I have no idea how can i do that... I builded the rest of my web application by myself but this is very complicated for me.
For example i need to know how can i accept incoming emails first... and where? in which email address my web application will accept these emails...???
Then how i will get them from there? How i will process them and how i will store them in my database?
Please help me with an example, some piece of code, anything!
Any help is accepted.
Im not an expert so a piece of code will help me a lot.
Thank you in advance!
You basically have two choices:
Run an SMTP program (such as Postfix or Sendmail) on your server to receive the emails, and use procmail to pass them to your code
get an email account on an external host service and retrieve the email using one of the POP3 client packages for PHP, such as pop3class
Option 1 is much harder to do, and you have to learn about administering an email server, which is not a trivial task. Option 2 is relatively easy and is the one I'd recommend.
Easiest way would be to setup a regular email address with some freemailer and then check this account.
A start for this might be the POP3-class of PHPMailer.
Can anyone suggest the methods I could use...
I m on shared hosting now (cpanel)... I have access to perl modules, ruby, (No idea how they work)
The IMAP extension is used for that. Either by having a real mailbox you check, or by letting the mailserver pipe emails to your your script & parsing the parts of the email with the provided funstions.
PEAR_Mail_MimeDecode class from Pear. Is the real solution.
Possible Duplicate:
Process RECEIVED email attatchment with PHP
If you are a on a shared hosting system it is possibly easiest to let someone like http://cloudmailin.com or http://smtp2web.com/ send the email to your app via a webhook.
You will then need to use something like Mail_MimeDecode to actually parse the message you receive and extract the content you want to use.
I guess it should be a common technique,
However, I tried the following two options:
1) Using my existing POP3 PHP client to access my local mail account. I am getting a "could not connect". Same code works if I run it with my localhost connecting to GoDaddy's pop3 server
2) Parsing the local mbox file - I can't figure out if I can access it, seems like I can't.
Any good ideas of which approach should be best here?
I'd go with the POP3 option. It should work once you get the right port/host etc.
The other option will result in you duplicating a large part of the functionality already in the mail server, and its quite likely you'll have minor bugs in it resulting in emails not displaying properly, or worse, corruption in the mbox.
If you do go with 2, try to find a library for doing the mbox bit!
Zend Framework has a mail component, that allows you to read from various sources.
Seems like I have this figured out. Shared hosting (GoDaddy specifically) does not allow direct TCP connections anywhere, including their own POP3 server. Looks like I can't be able to access the mbox file directly either. So I figure it is just not going to work.
Thanks all repliers!
Maybe there are OTHER inexpensive shared hosting plans that provide this option...