Email provider forwarding email to PHP script?

Does anybody know an email service provider which can forward received e-mail to a PHP script?

Examples:

1. All emails sent to blueman@emailserviceprovider.com will be automatically forwarded to:
www.mysite/bluescript.php

2. All emails sent to greenman@emailserviceprovider.com will be automatically forwarded to:
www.mysite/greenscript.php

etc.
PeterDelphinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Usually this is done with an email "pipe" script.  Your hosting provider can help you set one up.  The pipe receives the entire message, including all of the headers and the body of the email.  Here is my teaching example of a pipe script.  Please read it over carefully for understanding, then post back with any questions.

#!/usr/bin/php -q
<?php // /email_pipe/index.php


// THIS IS AN EMAIL PIPE SCRIPT.
// THIS SCRIPT IS STARTED AUTOMATICALLY FOR EACH MESSAGE.
// NOTE THAT THIS SCRIPT IS ABOVE THE /public_html/ DIRECTORY TO PREVENT ACCIDENTAL EXECUTION


// --> HOW DO WE KNOW WHICH EMAIL MESSAGES GET SENT HERE?
// THIS SCRIPT RECEIVES MESSAGES SENT TO email_pipe@your.org
// CREATE AN EMAIL MAILBOX EXCLUSIVELY FOR AUTOMATED PROCESSING.
// SET UP AN EMAIL FORWARD FOR THAT MAILBOX IN cPANEL->EMAIL LIKE THIS:
// 1...5...10...15...20...25...
// |/home/{account}/email_pipe/index.php


// --> WHEN YOU UPLOAD, THIS SCRIPT WILL BE MARKED RW-R-R BUT THAT IS WRONG
// THIS SCRIPT MUST BE MARKED EXECUTABLE x0755
// YOU CAN USE FTP SOFTWARE TO CHMOD TO RWX-RX-RX


// --> NOTE THE FIRST LINE OF THIS SCRIPT MUST SAY #!/usr/bin/php -q STARTING IN COLUMN ONE
// 1...5...10...15...20...25...
// #!/usr/bin/php -q
// <?php ... PROGRAM CODE FOLLOWS


error_reporting(E_ALL);

// USE THE OUTPUT BUFFER - THIS DOES NOT HAVE BROWSER OUTPUT
ob_start();

// COLLECT THE INFORMATION HERE
$raw_email = NULL;

// TRY TO READ THE EMAIL FROM STDIN
if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin " . PHP_EOL;
}

// ABLE TO READ THE MAIL
else
{
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}


// REMOVE MULTIPLE BLANKS - AND OTHER PROCESSING AS MIGHT BE NEEDED
$raw_email = preg_replace('/ +/', ' ', $raw_email);

// SPEW WHAT WE GOT, IF ANYTHING, INTO THE OUTPUT BUFFER
var_dump($raw_email);

// CAPTURE THE OUTPUT BUFFER AND SEND IT TO SOMEONE ELSE VIA EMAIL
$buf = ob_get_contents();
mail ('you@your.org', 'EMAIL PIPE DATA', $buf);

// PREVENT ANY BROWSER OUTPUT - MAY CAUSE ERROR RESPONSES AND BOUNCED MESSAGES
ob_end_clean();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterDelphinAuthor Commented:
Thanks, I will check back with my hosting provider (1&1) whether they can make this work. (I don't have a root server or dedicated server there, just a hosting plan with PHP. Or does anybody have experience how to make this work on a 1&1 non-server hosting plan?)
0
Ray PaseurCommented:
I've used the exact PIPE script above on LiquidWeb shared hosting, so I know it can be done.  Some hosting companies will have a control panel that you can use to set it up.  But I would not waste any time experimenting.  The hosting company will know the details, and that's what you're paying them for!

Be sure to put your own email on line 62.

You might want to add phpinfo() to this script.  The email you receive will be a jumble of hard-to-read stuff, but there will be nuggets of gold in there.  For example, your file paths will be different from the paths in the web root directories.  You should still be able to access your data base, but the connection and selection variables may need to change.

You cannot use cookies or the PHP session in any meaningful way inside a PIPE script.

HTH, ~Ray
0
PeterDelphinAuthor Commented:
Still waiting for an answer from my hosting provider.
0
ravi singhCommented:
I need Help about received email by mx records. in php script.
ex.
1. i have two domains example.com and domain.com.
2. i want to received all example.com's emails at domain.com by mx records.
3. i created 2 subdomain and point mx records by it a.domain.com and b.domain.com.
4. it's working correctly for domain.com but face issue with example.com domain because of remote received emails.

So how i can resolved this issue?

Thanks in advance
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Servers

From novice to tech pro — start learning today.