The past few days I've been trying to find out how I can save emails as drafts using php. I've created an emailaddress that uses imap (and resides on the same server).
What I would like to do is to use php to create an email and store it in the drafts folder. These emails would then be recognized by the email client (ms office outlook in this case) so they can be editted and send from the email client.
I've found some interesting information about the imap functions from php, they let you send mail, but I can't really figure out how to store them in the drafts folder (to which I have write access). I can actually find and read the emails, I save as drafts in my email client, using my ftp connection. However they make use of UID and message-ID's and such which I don't understand where they come from.
My questions:
- how could I create email drafts
- How does a new UID or message-ID get created, and how would I use them for my email-draft file?
Help is much appreciated, thanks.
Yorian
Have you checked if the proper extension is installed? To use the php imap functions the php5-imap extension must installed. You can check this by using phpinfo(). When there stands nothing about "imap", the extension is not installed.
Look into imap_setflag_full. there's a \draft flag.
AFAIK you can use imap_append() to store the mail in the INBOX.Draft mailbox (function.imap_append)
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 want to process incoming emails to an address and insert them into a mysql database. I am using a grid-service media temple host with SHH access but I have no idea where to start. I also want to store attachments or copy them to a directory on my host and save the url in the database.
Why not pipe the emails instead of using imap_open()? This would allow you to access the email immediately as it comes in, and then decide if you even want it stored in the inbox.
The simplest way to process incoming mail in PHP is imap_open(), which you can use to open a mailbox, either using IMAP4 or POP3.
You would need to run your script periodically, or at least regularly run imap_ping() to 'poll' for new messages.
Since you say you don't know where to start, my one suggestion would be to look at the inbound email service offered at Postmark. I believe there are several such services.
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 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.
I have a need to read the 'body' of the most recent email received using PHP (not interested in sender, etc...), but I am not at all sure how to do this. The mail server uses IMAP
http://ryerson.ca/ccs/email/rmail/clients/ConfiguringMozillaThunderbird.pdf <--Uses the same server described here. (This is not for my personal mail, its to read data and post it to a website. I would rather not use email to acheive this, but I do not have a choice here.)
Any idea how to do this? Code Examples? Anything is appreciated
The PHP IMAP Extension should provide you with what you need, assuming you have it or have the ability to install it.