Upload images via e-mail

Hello,

I'm trying to write a dead-simple PHP script that would allow me to e-mail an image (as an attachment) to an e-mail address on my server (e.g. uploadimages@myserver.com) and then have the script upload/save the picture to my server.

How could I do it (or, alternatively, where can I find a dead-simple PHP script that already does this)?

Thanks.
NeedExpertHelpAsked:
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.

msaqibansariCommented:
0
NeedExpertHelpAuthor Commented:
Thanks for your reply.

What's a PIPE script?
0
msaqibansariCommented:
PIPE script is a server-side script written in your favorite language like PHP that read email content and parse image header and content and write it hard disk.

If you're using CPanel then there is an option to forward email to PIPE script e.g.
http://kb.siteground.com/article/How_to_pipe_an_email_to_a_PHP_script.html

If you're working on Linux environment do the following steps.

Step 1. create a new email address e.g. uploadimages@mydomain.com
Step 2. Forward emails to your script written to handle email content e.g. /home/myusr/pipe.php
Step 3. Pipe.php is your file that parse image content from email.

Following URL have briefly describe this process.
http://activecampaign.com/support/tt/index.php?action=kb&article=145

Thanks
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

NeedExpertHelpAuthor Commented:
Thanks again for the additional info.

I will give it a try via cPanel and report back.

Where can I download the PIPE script in PHP?

Thanks.
0
Ray PaseurCommented:
The "dead-simple" part is going to be the issue.  It will not be dead-simple once you have email involved in the process.  So please help me understand something more about your requirement...  

If you have an image on a client computer that is capable of handling email, would you not also expect the client computer to he able to handle HTTP protocols?  And it follows that if you can use HTTP, you can use HTTP to access an image upload script on the server, right?  So what is the advantage of attaching the image to an email message, when you can simply upload it to the server with a file-upload script?

Thanks and regards, ~Ray
0
NeedExpertHelpAuthor Commented:
Ray, the answer is as simple as the script I'm looking for:  not all cell phones are compatible with type="file" uploads.

Any word on where I might find the PIPE script?
0
Ray PaseurCommented:
OK, that makes sense.  Flickr can do this sort of upload via email.  Each Flickr client has a unique email address so the pictures do not get mixed up.  Various combinations of info in the subject line can be used to identify the photos that are sent to Flickr via email.

A sample PIPE script is contained in this link:
http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/

It appears that all you need to do is set up your "pipe" with a destination script.  The destination script reads from stdin.  Then the fun begins.  What do you do with the input that comes through the pipe??

A similar question and answer is here, however I have not evaluated the quality of the answer:
http://stackoverflow.com/questions/114953/how-to-get-email-and-their-attachments-from-php

And these look interesting:
http://www.phpclasses.org/browse/package/3169.html
http://www.hotscripts.com/listing/email-mime-parser-decoder-in-php/
http://www.bucabay.com/2009/web-development/incoming-mail-php-mime-mail-parser/

Best of luck with it, ~Ray
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
Ray PaseurCommented:
Since you asked this question, I have had occasion to set up a PIPE script of my own.  Here are the essential moving parts.  HTH, ~Ray
#!/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
 
$script_start_time = microtime(TRUE);
error_reporting(E_ALL);
ob_start();
 
// DATA BASE CONNECTIVITY, CONSTANTS, FUNCTIONS, ETC
require_once('config.php');
 
// TRY TO READ THE EMAIL FROM STDIN
if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin \n";
    die();
}
 
// ABLE TO READ THE MAIL
else
{
    $raw_email = '';
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}
$raw_email = preg_replace('| +|', ' ', $raw_email);
 
// ETC ETC...

Open in new window

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
Web Development

From novice to tech pro — start learning today.