Update text on a website by an e-mail - php

My client is a restaurant that needs to change a paragraph section (<P>) every day for specials.
There are many people that will be handling it so I have to make it as easy a possible.
I don't think teaching the whole staff how to use a CMS is feasible, so I thought it would be a good idea to make something like an email service, that only updates that bit of text.
So in other words the staff would just have to send an email, and the server would somehow change the text on the HTML page for that day.
Can I do this in PHP code maybe?
I am also open to other ideas to something easy, like a simple login system to just change that bit of text.

I wouldn't recommend setting the text by e-mail. E-mail is an ugly, UGLY format to process, especially if it is sent by humans on every type of broken e-mail clients. The half of the e-mails will be invalid HTML, the other half will be tabulated unimaginably, the third half will contain signatures and there are so many more halves :)
And explaining the e-mail format you expect to the staff (utf-8 plain text with no signatures, etc...), and how to set it on their Outlook Expresses, Netscape Mails, and web clients you never even heard of, will be just as difficult as explaining a CMS.
What I would recommend is a simple form instead. If you open the form the current text could show up in a text field, and upon posting back the form you save it's contents on the server.
You would need to store this text somewhere. There is very few servers that host web applications without some form of database backends, so I'm pretty sure you have some kind of database to store your text in.
Also the form would need some kind of password protection. The easiest would be IMHO to password protect the folder where your php is. It's not too hard in Apache.
Check this link: http://www.groovypost.com/howto/htaccess-password-protect-apache-website-security/
I'm not familiar with your experience in PHP, but I hope you can make a form to edit a database record. If not, then please use google, there are tons of tutorials on it.

You could use imap extension http://php.net/manual/en/book.imap.php it allows you to read emails from email box. usualy, programmers create keywords that act like commands to script, for example, if title of email is match pattern UPDATE pageID then it will process email body as content for this page.
This script will be running with crontab, which is scheduler for unix OS. So you can run it every 1 hour for checking new mail.

maybe your client could send an excel sheet and you parse this email attachment on server side with php.
https://code.google.com/p/php-excel/

One option is to use a blogging platform to post the latest specials. You could then use PHP to grab the RSS output (last feed item) and populate the website. This would take care of the form, log in and security part. It also gives the client a running history.
(if you want to go this route I can post an rss reader php script to help you out)
Alternatively, if you decide to go the email route, put the text between something like this:
<!-- PUT PARAGRAPH HERE -->
Here is today's specials.
<!-- /PUT PARAGRAPH HERE -->
Can be anything really, but bookending it with something constant you can search for in the string will help avoid many of the issues mentioned by #SoonDead above. PHP can convert it into something consistent, but you'll need some php knowledge to make it work.

Related

Create form and submit as PDF in dreamweaver

I'm helping my father with some technical stuff for his business and can't seem to find an answer to a seemingly simple task. He has given me several printed forms that he would like to put on his website for clients to fill out, rather than having them do it physically and scanning the form to a PDF each time.
I have figured out how to create the form in Dreamweaver and submit to an email, but I'm trying to figure out a way to submit the form via email as an attached PDF file that shows the contents of the form exactly as it looks on the website (logos, fields, etc.), while saving it with a unique name (such as last name or date on the form).
I have a little experience with PHP but not enough to figure out how to write a script for this purpose or even where to start on a task like this. Any suggestions or advice would be greatly appreciated!
Thank you!
Consider using PDFlib as a PHP library to do this. Refer to This guide to install it. All of the functions I will mention are from php.net
First, you'll need to call PDF_begin_document to begin the document under a specified filename. You may then use PDF_setfont() to set the font to use(Refer to http://www.php.net/manual/en/function.pdf-setfont.php#10254 for the core fonts you don't need to embed, it looks as if they may not support size>12)
Create a page with PDF_begin_page_ext()
You can then use PDF_add_textflow() to add text from strings(Use string manipulation as it is easier then groping 5-subroutine-deep with textflows, I think \n is supported)
End the page after adding your textflows with PDF_end_page_ext()
Be sure to use PDF_end_document() to end the document. When you began the document, it took a filename. You will find the PDF there.

Anyway to automatically extract URL from a link in a monthly email?

Basically I'd be getting an email once a month that contains a link and some text. I need to be able to grab the link from the email and somehow get it to submit the URL to a database. I can do the database stuff on my own, so I just need to know if it's possible to automatically retrieve the URL from the email every month.
If this isn't something I could do with PHP, what other languages could I do it that are common to web servers? Or maybe there's a service that does this somehow?
I don't know if it's the proper way or not to accomplish your task, but this is something that will work.
Say that you want to check your email for new mails each 1 day, then set a cron job each 24h that executes a php file (you can set it as frequent as you want but some web hosting services limit it). In this file you need the code for retrieving your mail (whatever you use) and some code to parse the email and differentiate regular text from the link.
To do this, if the link is a regular html link, just search for "http" and then copy everything after it to the next " ", if it's user-written, you might get to work much more to parse it and avoid bugs, or you might get a different protocol. Just work the file and if you have any question come back to ask again.
EDIT: To answer the actual question, YES, it is possible using cron jobs or some less common alternatives

Heuristic to detect if an HTML email was read

I am looking for creative heuristics to detect if an HTML email was not just opened, but also likely read.
Currently, we embed an img tag linking to a PHP script, which marks anonymously in the database that the email was opened. (We can assume here that the users we're interested in told Outlook it was OK to display the images.)
This method is okay, but it's hard to tell what it means - if they clicked the email just to get it marked as read, if they keyed through it while skipping through other mails, or if they genuinely read and enjoyed the email.
My latest try was to implement a delay of 10 seconds on the image download before making the database call marking the mail as read, however it seems that Outlook finishes the request in the background, even if they skip out of the email. Does anyone have any creative recommendations that may work better?
It's kind of unethical in my opinion to do this without your user's knowing. That's why so many email clients go to measures to protect against this.
I know this might not really help you, but if your user genuinely read and enjoyed the email couldn't you just add an HTML anchor in the email that they can click on to go to your website and you can add a tracking code to that to figure out who it was / which email address clicked on the link at the bottom of your email. Something along those lines just seems like a better method to me. Maybe that's just me though.
Hmm, tough one without the use of javascript, and as we know, most email clients have their security too high to use javascript.
Not putting much thought into it, could you use PHP's shutdown function, and have the image "loop" load....basically meaning that the image will never completely load because we are stopping it on the server side with a loop. Will Outlook still try and download the image after a timeout - will it timeout?
It seems like you are dealing with two different issues...trying to harness Outlook and trying to do something that most people don't want.
This is why there are offers and links like "click here for 10% off coupon" or "read more".
From a marketing standpoint this would be a true test if people are interested in your emails....but I guess that wasn't your question ;)

Edit an email subject line (IMAP)

I am trying to integrate IMAP email processing with another in house system that bases what it uses off of the subject line / email content.
We need to be able to change the text of the subject line before moving the email to a new folder. What/where would be a good place to start?
I've had a look around and it IS possible in a manual sense, via a thunderbird plugin or using outlook. I just can't seem to find a relevant example in PHP, or any other language for that matter. I also hear the idea is flakey at best as you need to modify the email content and upload it back to the imap server.
The outlook implementation seems to delete the original and save a new one to your IMAP folder on the server.
Side note: Yes I know it is a weird requirement, and although forwarding the email to ourselves then moving it is our fall back plan it is not much liked as it moves original headers useful for things like reply-all.
Any suggestions appreciated.
PS If I'm blind and there is something obvious I'm missing in the manual let me know.
Do you already have any code built to handle the email processing? IMAP subject line information is stored as a header so you would need to utilize the PHP functions of imap_headerinfo() and/or imap_fetchheader() depending on the functionality you're looking for to achieve this. You could have PHP check each message header and if it matches X format, remove the message, and create a new one with the appropriately modified header information.

Is there a PHP script to mail forms for beginners for free?

I have a place where I want users to submit emails for newsletter subs and a place to submit an entire contact form. Zero php knowledge outside of know that it can do what I need.
There's a mail function built-in, take a look at
http://php.net/manual/en/function.mail.php
you will however, need to format the email body with the form data posted, of course.
Check out FormToEmail. From their site:
FormToEmail is a PHP form mail script.
It comes in a free version and a Pro
version. It processes web forms and
sends the contents of the form to you
by email. It will process any form. It
doesn't make forms but it comes with
HTML code for a basic contact form
that you can use on your website. It
is very secure and cannot be hijacked
by spammers. It is very simple to
install, you only need to add your
email address to it. Step-by-step
instructions written in plain English.
Actually, you don't need to do any php programming to create a such a setup. There are plenty of mailing list software apps available and you can grab a formmail script (like the one from Matt's Script Archive) and build the html with the right fields.
Use the mail function.
However be aware that you need to specify the correct headers yourself if you want to use html in your emails!
A common beginner's mistake is assuming you can simply use html tags with mail and it should work automatically.
Figured this was worth mentioning, since you are wanting to do a newsletter. If you try sending the email, and the raw html tags seem to appear in the message, this is your issue :)
As someone who is a PHP know-nothing, I often look for easy solutions to complex problems. Using a super simple PHP form can have some downsides such as getting massive amounts of spam if you don't have any measures to prevent that, setting up those measures is hard to do if you do not have any knowledge of PHP.
Here is what I found, there is a script here: http://www.dagondesign.com/articles/secure-php-form-mailer-script/
that you can download at no charge and the developer seems to have a lot guidance on how to install and use. I was able to set it up and get it to work.. not without having to spend quite of bit of time reading and trouble shooting. Hope that helps you.

Categories