1

I'd like to make something that receives an email, gets the attachment from the email, resizes the image, and emails it back. I wanted to make a small web application that can do this.

I understand this will most likely be a lot of work, but I want to learn from the ground up how to do this. Can anyone point me in the direction I might start, or give me some sort of a rough outline on what I may need to do?

I want this to be in PHP, since I already have my own shared web host.

Ricardo Altamirano
  • 14,650
  • 21
  • 72
  • 105
Shawn
  • 11
  • 1

2 Answers2

1

It seems as if there is 3 components to your request

  1. Receive email with attachment using PHP

    This is not possible with just PHP. To receive email you need a Mail Transfer Agent that is listening on the correct port. Connecting such to PHP doesn't really make sense.

  2. Resize an image

    PHP can do this using the GD libraries as long as they were compiled into apache or added in as modules later on. http://www.bitrepository.com/resize-an-image-keeping-its-aspect-ratio-using-php-and-gd.html

  3. Send an email

    This can be done with the mail() command. http://www.w3schools.com/php/php_mail.asp

Maybe you want to instead make a webpage where your father can upload the image and it shows the resized image on the webpage and offers a download link.

Community
  • 1
  • 1
Nick
  • 3,096
  • 3
  • 20
  • 25
  • Using PHP to handle incoming emails makes a lot of sense, i.e. mobile upload email addresses used by Facebook. – Arvin Feb 08 '11 at 06:06
  • http://cloudmailin.com might help you to fullfil step one without having to leave the php environment and start configuring email servers – Steve Smith Feb 08 '11 at 10:39
0

That's not a common task for PHP scripts. Receiving emails needs a workaround. You can either use a cron script to poll a pop3/imap account, or set up procmail if you have a more professional hoster. Check out this answer for a few interface ideas: How do I receive email and process it in a web application

You then need an email decoding library. Attachments in emails are encoded as multipart/whatever entries. Use a readymade library, which will also ease sending the reply email. (fMailbox and fEmail as mentioned in the above link might be a good match)

The resizing of images is the easy part. Check out the GD image functions http://www.php.net/manual/en/function.imagecopyresized.php and the many examples.

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291