Send photo to email bot, upload photo to website - php

I am constantly taking the following steps, and I know there's a way to automate this:
emailing photos from my phone to myself
saving those photos to my computer
uploading the saved photos to a website
Is there a way to write a script (perhaps in PHP), that does the following:
listens to any emails sent with
attachments to a bot email (ex:
bot#site.com)
automatically uploads any attachments sent to that email to the site? (ex: upload to www.site.com/photos)

If you must have it on your server, there are a couple approaches.
PHP can check a mail account via POP3 or IMAP. You could have a cron job running that fires off a PHP script to check a secret e-mail account every few minutes and process there.
Incoming e-mail can also be piped directly to a PHP script
I just use Flickr, and they give you a random e-mail address #flickr.com that you can send attachments to and have them automatically processed. That's the fastest and easiest option if you're okay with Flickr hosting your photos.

If your phone can go online, why email them and not directly upload photos to your site? Many mobile platforms have clients for adding entries and images to blogs and hosting services like Flickr. Maybe there is such a client right for your phone?
Script on its own is a passive thing. I'm not familiar with PHP though but... If you have a page open 24h/day, you could put there JavaScript calling some server method in loop once in 10 minutes to check for emails and if there are attachments just initiate asynchronous form post.
Would be great if you could elaborate and whatever you have at your disposal. Is it your site and you have administrative access or you just a user? Is there maybe an API to use in addition to just HTTP POST?
I believe, unless it's your own site, you will need somewhere a PC running all the time with either a browser window or a desktop program open.

Related

run phpmailer in the background/new tab or any method without interrupting web UI process

im building a photobooth app whereby a user can take photos and email those photos to themselves, i use phpmailer smtp, the only parameters i pass to phpmailer are the email and the photo names ( because i saved the photos in the server folder right after the photo is taken, therefore i just need to handle the photo name).
the process goes like this: after taking photos, the user enters and submit their email and selected photos by clicking 'send' to send the photos to their email, it will then pass these parameters to the phpmailer to send the photos, and then goes to a thank you page. however, when the user clicks 'send', the process to connect to gmail and attach the photos takes a very long time and the UI is on a loading state, therefore i tried different ways to run the phpmailer process: like open the thank you page after click 'send' and then running phpmailer in a new tab (but i cannot keep the tab focus on the thank you page since js disabled opening a new tab in the background); or after click 'send', redirect to phpmailer but run the thank you page first (however phpmailer will still run the slow email process first before opening the thank you page).
any methods that are simple to use and can help to solve the slow email process? as long as it doesnt affect the UI whereby user needs to wait for the email process to complete before doing anything else, then i will be happy to try
ADD ON: it has to be a public email because my client is not gonna use their corporate side to operate this as there's too many security procedures, and btw im doing this on a windows system. BTW, as a photobooth users, people would want their photos as soon as possible, and using queue and cron is hard to inform the user when the message is sent, therefore that may not be a feasible solution
ADD ON: i cannot store user's email address in any db due to security, so i cannot store the emails somewhere and then send them later using any task scheduling method
SMTP is generally not safe to use during web page processing as it is often unacceptably slow, as you're finding. The solution is to not send directly to remote servers, but to queue locally, which is usually predictably and reliably fast. The most straightforward way to do this is to install a local mail server, such as postfix, and send your messages via SMTP to localhost. This will usually submit messages in a few hundredths of a second, plenty fast enough for most purposes. On most Linux distributions this is no more complex than apt install postfix, and then simply calling $mail->isSMTP() (with no other SMTP settings - defaults should work) in your PHPMailer script.
A more complex approach is to store the fact that you need to send a message in a queue (which is essentially instant), then use a separate process or scheduled task (cron) to pick up that info and send the message. This decouples the sending from your page processing, making it fully asynchronous. The only problem here is that it becomes more difficult to inform the user that their message has been sent.

How does a php script on a contact form access the user's email?

This tutorial teaches you how to create a contact form for a website using php script: http://www.boutell.com/newfaq/creating/email.html
But how does this work? How does the script access the user's email account to send an email? How does such a form work without a server? (For example if I put my website on github pages which only handles static pages, how does this php script work?)
there's no way to make the server do something if the server does only throw HTML pages out.
You need some programming language (PHP in your tutorial) to process your code, it has to be installed in the server and accessible to you. It will run your code, decide what to do and do it (by the way to actually send the mail you will need the proper PHP modules available). In this case the script will not use the user's email account to send the mail: it is the server who sends the mail, not the user's client. You will receive an email from your server, so watch out to ask the user for his email, otherwise you will not be able to get it in any way.
If you have no serverside intelligence capacity, just use your user's tools. Which means stuck with the mailto scheme (as the tutorial's first examples show). Then the user's computer will send the email (with the drawbacks the tutorial points out)
It uses the mailto: URI scheme which is opened by your mail client just like skype: scheme is bounded to your Skype client.

uploading pictures by email

I was looking for uploading photos by email documents (in php) but couldn't find good one.
Is there any easy ways to upload pictures/photos by email?
ie. steps,
1) on mobile devices, email a picture to private-email#domain.com
2) copy the picture into our server like facebook or flickr
ps. I run apache servers, mysql and php
There are a number of different approaches to receiving email with PHP. The main options are:
Retrieve the emails via background job (cron etc) and IMAP/POP3
Run a mail server and make that send the content into the app directly (pipe it into php)
Use a third party service
I wrote a blog post that was for Rails here, although it's for Rails pretty much all the principals still apply to PHP and translate directly.

How to automatically put email content on the webpage

I've been receiving a lot of spam emails and I want to post them on my website to serve as a warning for others not to believe it. Since I'm too lazy to login to my email account and check. I'm thinking to write a script in php (since this is the only one i know)that logs in to the mailbox at regular intervals, retrieves the content of the e-mails and then post it to my website automatically. Any suggestions on what would be the best approach to accomplish this task? Do I have to do PHP socket programming?
Thanks
I suppose your emails are filed under a Spam or Junk folder. You may want to set up a Cron job that runs periodically to read via IMAP or POP.
You may want to check what're the protocols supported by your service provider and where exactly you want to post the information to - a database or HTTP POST.

How do I maintain a constant reference to an email on Gmail while access a copy of it from my Google App application?

I'm working on shifting my local web application to google apps. I have an account already for google apps for business and right now I need to work on the functionality of interacting with email.
Let me give a synopsis - my web app currently was set up that a cron job would download all emails from a set mailbox into a database at short intervals and when each message would be entered they would be assigned a specific ID and we would be able to use that ID to refer to that message in our application wherever we would require. So basically our applications mail section gave the illusion of being a webmail client when nifact it would retrieve from a database. I'm interested in a solution with google apps on a similar case.
The thing is that the application initially when the cron job runs - not only does it download a the email from the mailserver but it would also delete the email from the mailbox. So basically we would refer to the email on our local database as that is where it would exist.
Now however I don't want to delete the email form the inbox at all. Infact I would like to set it up such that I can maintain a reference to an email on my gmail inbox and still have a copy in my local system or at the least a basic link to the email. The thing is that from my programming with email webclients I havent been able to find what is a UNIQUE ID for emails in the mailbox which could be used as a way to identify them from an external application - emails seemed to be numbered by sequence and the sequence changes when an email is moved between inboxes. The UID or unique ID value seems misleading as it is just a sequence number for that email which can change if earlier emails are deleted or moved about.
What would be the best way to do this?
Are you sure about the fact that the id changes? I just archived a message that was in my inbox. (I had copied the link beforehand). Then I took the link, and used it in a completely different browser (first time was FF, second time was Chrome). It pulled up the same e-mail.
Google's IMAP server supports a proprietary X-GM-MSGID command which allows retrieval of a message's Gmail UID.
https://developers.google.com/google-apps/gmail/imap_extensions#access_to_the_gmail_unique_message_id_x-gm-msgid

Categories