Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Upload images via e-mail

Posted on 2009-07-11
8
240 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:NeedExpertHelp
  • 3
  • 3
  • 2
8 Comments
 

Expert Comment

by:msaqibansari
ID: 24830011
0
 

Author Comment

by:NeedExpertHelp
ID: 24830041
Thanks for your reply.

What's a PIPE script?
0
 

Expert Comment

by:msaqibansari
ID: 24830270
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:NeedExpertHelp
ID: 24830371
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
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 24831265
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
 

Author Comment

by:NeedExpertHelp
ID: 24831282
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
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24831712
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
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 25335102
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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question