Quick Search:
 PHP Code: Automatically process email Jump to:  
Category: >> PHP Code >> Automatically process email  

<< 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 with 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 one

Comment: (none)

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

PHP with CLI enabled
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 
This will forward any email sent to [email protected] 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
// Need PEAR installed
REQUIRE_ONCE 'Mail/mimeDecode.php';
// read email using stdin
$fd = FOPEN("php://stdin", "r");
$email = "";
WHILE (!FEOF($fd)) {
        $email .= FREAD($fd, 1024);
$params['include_bodies'] = TRUE;
$params['decode_bodies']  = TRUE;
$params['decode_headers'] = TRUE;
$message=NEW Mail_mimeDecode($email);
// Who is it from
// Get Subject
// Get Message Body
// Get and Save the Attachments
FOREACH($mailObj->parts AS $key=>$val):
                $fd = FOPEN($tmp, 'w');
                FWRITE($fd, $tmpObj->body);
} //endforeach;
// end of contents of process.php
Posted by Christian in Php at 07:04

   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org