Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Automatically process email Jump to:  
Category: >> PHP Code >> Automatically process email Bookmark and Share

<< lastnext >>

Snippet Name: Automatically process email

Description: Automatically process an email with attachment(s) using PHP and PEAR Mail class.

Also see:
» Send iCal Email Meeting Requests using...
» Is email deliverable?
» Email attachments with PHP mail()
» Email w/ attachments class
» Heavy-duty SendMail function
» Use SendMail
» Live validation of email address
» Fake email addresses
» Validate email address #3
» Validate email address #2
» Validate email address #1

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?PHP
 
/*
Prerequisites:
Linux/BSD
PHP with CLI enabled
PEAR
Sendmail with individual user account
 
Aim: Save attachments to server storage.
 
1. Setup sendmail account to forward to PHP script.
 
In the home directory (/home/user) on the foo.bar machine make 
and edit a file called ".forward". In this file put in the 
following.
 
|"/dir_to_php_script/process.php"
 
This will forward any email sent to user@foo.bar.com to the 
php script.
 
2. PHP script to process email "/dir_to_php_script/process.php"
[Don't forget to chmod 755 process.php]
 
*/
 
// begin contents of process.php
#!/usr/local/bin/php
<?PHP
// Need PEAR installed
INCLUDE('Mail.php');
INCLUDE('Mail/mime.php');
REQUIRE_ONCE 'Mail/mimeDecode.php';
 
// read email using stdin
$fd = FOPEN("php://stdin", "r");
$email = "";
WHILE (!FEOF($fd)) {
        $email .= FREAD($fd, 1024);
}
FCLOSE($fd);
 
$params['include_bodies'] = TRUE;
$params['decode_bodies']  = TRUE;
$params['decode_headers'] = TRUE;
 
$message=NEW Mail_mimeDecode($email);
$mailObj=$message->decode($params);
 
// Who is it from
$from=$mailObj->headers['from'];
// Get Subject
$subj=$mailObj->headers['subject'];
// Get Message Body
$body=$mailObj->parts[0]->body;
$gather="From:$from\nSubject:$subj\nBody:$body";
 
 
// Get and Save the Attachments
FOREACH($mailObj->parts AS $key=>$val):
        $tmpObj=$mailObj->parts[$key];
        $tmp=$tmpObj->d_parameters['filename'];
        IF(!EMPTY($tmp)):
                $fd = FOPEN($tmp, 'w');
                FWRITE($fd, $tmpObj->body);
        ENDIF;
 
} //endforeach;
 
// end of contents of process.php
?>
 
Posted by Christian in Php at 07:04


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 162 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?