Processing Incoming Email Using a PHP Script

So, I'm trying to figure out how to send an email to an address, such as something@whatever.com , and instead of going there, it is sent or sent to a script that I create to read the contents of the email and store the contents in a database. Any suggestions on how to do this in PHP?

Thank!

+2
source share
2 answers

Here you can use the code you can use to jump:

// set user to check
$strUser     = "username";
$strPassword = "password";

// open
$hMail = imap_open ("{mail.yourdomain.com:143/notls}INBOX", "$strUser", "$strPassword");

// get headers
$aHeaders = imap_headers( $hMail );

// get message count
$objMail = imap_mailboxmsginfo( $hMail );

// process messages
for( $idxMsg = 1; $idxMsg <= $objMail->Nmsgs; $idxMsg++  )
{
    // get header info
    $objHeader = imap_headerinfo( $hMail, $idxMsg );

    // get from object array
    $aFrom = $objHeader->from;

    // process headers
    for( $idx = 0; $idx < count($aFrom); $idx++ )
    {
        // get object
        $objData = $aFrom[ $idx ];

        // get email from
        $strEmailFrom = $objData->mailbox . "@" . $objData->host;

        // do some stuff here
    }

    // delete message
    imap_delete( $hMail, $idxMsg );
}

// expunge deleted messages
imap_expunge( $hMail );

// close
imap_close( $hMail );
+7
source

Two options:

1) , script (, procmail ..) , .

2) , PHP script IMAP, , , . cron .

+2

All Articles