Automating Order Processing - Using EMail
Overview
If you're NOT using PayPal, or your ecommerce provider will NOT trigger a script directly, then you need to set things up so the emails are forwarded immediately to the processing script.
Note, some webhosting companies offer the ability to forward emails directly to a script for you - check with your webhost.
This solution will work for just about all means of online payment, so even if you have your own merchant account, or choose a different provider than the ones discussed, you can still automate your website!
Processing emails consists of the following steps:
- Email arrives in your mailbox.
- A dot-forward file tells your mail program to send the mail straight off to a script.
- The script reads the mail, line by line and:
- Writes the current line to a log file. (This is so you have a log of the raw emails you've been sent - in case of problems)
- Stores any information you want from the line into a local variable. (If you don't know what variables are - then please read the chapters on programming before continuing)
- When the whole email has been read, the script then:
- Checks for any errors in the data. (The info read from the email)
- Writes the customer and sales data TO the Database.
- Gets the password for the product bought FROM the Database.
- Sends an email to the customer with the password to unlock the product they bought.
|
Email Setup
The email system you get with your webhosting account will allow a number of different mailboxes, and web-based access to them. Unless your webhost will forward emails to a script for you, we'll have to change the way your email system works.
If you've haven't already sent a request to your webhost for 'shell mail' to be enabled, then do it now!
Once shell mail is enabled, you'll be able to create the required dot-forward files. These are simple files that just say 'Mail for Recipient-X goes to Destination-Y'. (Prior to enabling shell mail - these would have no effect.)
Unfortunately this makes the whole sending and receiving of emails a bit messy. The solution I suggest is that you receive and send mails via different mailboxes:
- INCOMING MAILS:
emails to sales@yourdomain.com are FORWARDED to your most used email account (i.e. your Outlook / HotMail account). You read and store them here.
- OUTGOING MAILS:
responses, mailshots etc. must go via yourdomain.com's mail server. Otherwise you can't send mails as someone@yourdomain.com (it'd be someone@hotmail.com or whatever). You use a mail client such as Outlook or Popcorn to send emails.
You can use the same program to read and send emails, but they have to go through different accounts (mailboxes).
INFO:
1) You can get a mail client to access your shell mail mailbox, but it would only be able to access mails sent to your_username@yourdomain.com. It won't see the other recipients (like feedback@yourdomain.com etc.).
2) You can read emails at the Unix command line using pine. This is a full-featured mail client, but if you're not used to Unix, you might find it confusing.
3) With some mail programs i.e. Pegasus Mail you can specify that you read emails from one mailbox, and send them from another. You can set it up so the incoming mails (POP - Post Office Protocol) are from your Webmail (if it allows it), or ISP mailbox, and outgoing mails (SMTP - Simple Mail Transfer Protocol) go from your domain's mailbox. You do this by setting the 'Network configuration' for each identity appropriately. See Pegasus's extensive help system for more information on how to set it up to your requirements.
|
So, all the emails that are sent to your website addresses need to be forwarded to your own email address(es).
Dot-Forward Files
Dot forward files are small files that you place in your home directory - on your webserver: e.g. users/yourname/. The name of the file gives the email address it's dealing with: i.e. .qmail-bob is a file specifying where to send mail sent to bob@yourdomain.com.
You can send emails to:
- another email address
- a script or program
- a mailbox
Using the .qmail-default file you can specify one default (catch-all) destination where all mails go by default...
NOTE:
You cannot use the .qmail-default file to catch all emails to yourdomain.com, and send then to yourname@yourdomain.com because this creates a loop:
... i.e. when mail to yourname@yourdomain.com is received, the mail program sends it to yourname@yourdomain.com, when it's received it's sent on again... forever. (Actually, qmail notices that it's a loop and gives an error message.)
|
You need to create this default file and another file specifying that order confirmation emails go to our Perl script...
Create the following files:
- .qmail-default
Open a telnet window to your webhost and login (for more info see the page on Unix). You'll be in your 'Home' directory on your webhosting computer and you'll get a 'prompt' which looks like this:
[you@self you]$
We'll now create a file using the Unix cat command.
TIP: All Unix systems have a built-in help system of manual pages. These are accessed by typing man command (where command is what you want to know about). i.e. you can type man man to find out how the man page system itself works. Use the man pages to get a better understanding of the commands you use here! |
At the prompt, type the text in bold (substituting your email address for the example of course!). Note the initial '&' indicates that this line is a forward to an email address:
[you@self you]$ cat >.qmail-default
&you@yourmail-provider.com (Your email address here!)
Then press ctrl-d to end the file.
- .qmail-ebot
Now you need to create the forward file that'll send the confirmation mails to the script (substitute '/home/you/cgi-bin' for the path to your cgi-bin directory!)
[you@self you]$ cat >.qmail-ebot
|/home/you/cgi-bin/ebot.pl >>ebot.log 2>&1
Then press ctrl-d to end the file.
If you want to create more files - go ahead. (I.e. if there are a few people in your company, you'll probably want individuals emails forwarded directly to them).
Note that to forward to an email address, the line starts with an ampersand '&'. To forward to a script it starts with a pipe symbol '|'.
Click here to find out more about qmail.
Click here for a full line-by-line explanation, to read about, and install the free perl email order processing script.
|
|