Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using the PHP imap() function
Old 11-17-2009, 04:54 AM Using the PHP imap() function
Novice Talker

Posts: 9
Trades: 0
Ok here's what I want to do.. I want to write a script that will automatically catch all emails and auto-respond based on what is in the content of the email... For example I know how to create auto-responders but they send the same email everytime.. I want a script that first off checks the email account (imap()) and then responds based on the user email... eventually I would like to turn my server into a text sending server sending texts to cellphones (I can do that already) but I want it so users can send in a question from their phone and the server will answer them back correctly.

Any thoughts on how to go about doing this?
Mteigers is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-17-2009, 02:05 PM Re: Using the PHP imap() function
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
I know of two ways to approach this problem. One is to use PHP's IMAP functions to open a mailbox and reply to unread emails. The problem with the approach is that you would have to set up a crontab for the script. The second approach would be to intercept the email. The problem with this approach is that it requires some additional setup.

Here is a guide on intercepting email: http://tinsology.net/2009/01/interce...mail-with-php/

If you choose the imap path you'll need to decide what you want to do with the emails once you've replied to them. If you want to delete them, just use imap_delete once you've replied to it. If you need to keep it you can use the 'answered' flag to make sure you won't reply to the email a second time. Here is an example:

PHP Code:
$host 'localhost:143';
$user 'user@domain.com';
$password 'password';
$mailbox "{$host}INBOX";

$mbx imap_open($mailbox $user $password);

/*imap_check returns information about the mailbox
including mailbox name and number of messages*/
$check imap_check($mbx);

/*imap_fetch_overview returns an overview for a message.
An overview contains information such as message subject,
sender, date, and if it has been seen. Note that it does
not contain the body of the message. Setting the second
parameter to "1:n" will cause it to return a sequence of messages*/
$overviews imap_fetch_overview($mbx,"1:{$check->Nmsgs}");

foreach(
$overviews as $o)
{
     if(!
$o->answered// if the email has not yet be replied to
     
{
          
$recipient $o->from;

          
//use imap_mail() to send your message
 
          //mark the email as answered
          
imap_setflag_full($mbx$o->uid"\\Answered"ST_UID);
     }

The above code will reply to all unanswered emails, marking them as answered along the way.

More info on the imap functions:
http://tinsology.net/2009/04/accessi...map-using-php/
http://tinsology.net/2009/04/php-imap-notes/
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 11-17-2009 at 02:08 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-17-2009, 10:33 PM Re: Using the PHP imap() function
Novice Talker

Posts: 9
Trades: 0
Thanks for the help... so for the Cron Script would I setup the Cron Job to run the script you just gave me? And where might I go about defining the auto-response etc..
Mteigers is offline
Reply With Quote
View Public Profile
 
Old 11-17-2009, 11:41 PM Re: Using the PHP imap() function
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The code I wrote is just an example. I left a comment where you would actually send the message, but you would have to define what that message is yourself.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to Using the PHP imap() function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15341 seconds with 12 queries