Solved

Upload images via e-mail

Posted on 2009-07-11
8
236 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
Comment Utility
0
 

Author Comment

by:NeedExpertHelp
Comment Utility
Thanks for your reply.

What's a PIPE script?
0
 

Expert Comment

by:msaqibansari
Comment Utility
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
 

Author Comment

by:NeedExpertHelp
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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 108

Expert Comment

by:Ray Paseur
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now