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.
Related
I have special e-mail accounts on my web server (#mydomain.com). I want to run a php script automatically when one of these accounts get a new e-mail. For example: when info#mydomain.com address receives a mail, I want to run "receivedMail.php" file and read this new e-mail. I don't know where I will start or how can I do this.
You're wanting to pipe email received for a specific email address to a PHP script.
If your webhost has cPanel, this makes it very easy to setup. See:
http://kb.siteground.com/how_to_pipe_an_email_to_a_php_script/
Alternatively, if you don't have cPanel but have Exim mailserver, this will guide you on how to do this:
http://www.phpshare.org/articles/Piping-Incoming-Mail-with-PHP
Hope this helps!
You have to create a cron job calling your php file every 1 minute for exemple.
The script have to the derver and read the email.
This has nothing to do with web servers directly, Since web servers do not receive emails. So no .htaccess style files come into play. The email is received by a mail server, so that is where you have to get active. Two strategies are possible:
you use the possibilities to trigger an action as offered by your
mail server (typically the smtp server you operate). That obviously
depends on which mail server you operate, different software offers
different features.
you poll those email accounts on a regular base, using a standard protocol like POP3 or IMAP4. You can do this using any suitable client. When a new message is found whilst polling the account, then you trigger the action you wish.
Option 2. is probably easier to start with. So give it a try: create a php file which polls your email server. You can use the imap php extion for this, it supports all important email protocols. The extensions allows to easily detect and retrieve new messages. For each such message you can implement whatever action you wish. All that is left is to run this script on a regular base, say every 3 minutes, which is typically done using a cron system. There are many examples for this out there on google...
Have fun!
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.
I know you can send emails with PHP but, can you receive emails through PHP?
You can pipe incoming mails into a PHP script so you can process it directly. Evolt has an article on how to setup something like that. This can be useful if you want to activate scripts programmatically by sending Emails to it (like responses to a newsletter mail that unsubscribes the user).
If you just want to read mails using PHP, PHP has native functions to talk to IMAP, NNTP and POP mailboxes.
Take a look at http://cloudmailin.com it takes away a lot of the hassle involved with receiving the email and will send it directly to your app via an HTTP Post. We have quite a few php users using the system to receive email.
You could write a mail server in PHP that binds to a port and listens for incoming email.
But PHP is not the language I would recommend for tasks like this, and it would also be a hugely complex undertaking.
You can hook into an existing mail server as callback script, or periodically query a mail server via POP or IMAP. The latter option is the most common: run a PHP script that processes an email account via a cron task in intervals. See http://php.net/imap.
There is a great library that is based on IMAP extension: http://code.google.com/p/php-imap
Only a mail server can receive e-mails. You could read mail box formats (such as mbox or Maildir) to read e-mail using PHP.
PHP scripts functioning as IMAP/POP3 servers can receive e-mail sent to them.
i am searching for a way to read mail messages from a PHP application, including access to attachments etc. imap functions are not acceptable as a solution, as this application will handle mails with heavy attachments.
i have full access to the server's mail folder from php via filesystem. any thoughts?
I think you could use a combo of the Pear packages Mail_Mbox and Mail_mimeDecode. Use Mail_Mbox to read new mail from the inbox, one message at a time, and use Mail_mimeDecode to extract the attachements. All this will be done w/o IMAP. You can then save the read messages to a different mbox to keep the inbox clean.
Pear - Mail_Mbox
Pear - Mail_MimeDecode
I had a question like this a while back. See if any of the answers help you:
How to get email and their attachments from PHP
postfix + maildrop was the solution I ended up taking, It routes the emails through to a PHP script when it arrives and in my case, the PHP does something with the attachment. But I only needed to read each email once. If you need to be able to browse all the emails, you either need to store the results of maildrop or find another solution.
If you need to full access to all emails, POP and IMAP are popular choices because they do work. I'm not sure why you're against them.