Automatic Piping and Extraction of Email Attachment to a Database in PHP
$30-100 USD
Paid on delivery
I would like to pipe an incoming email through a PHP script automatically,? extract the email attachment and drop the contents of the attachment into a mySQL database.
## Deliverables
I would like a PHP script which automatically extracts an attachment from an incoming email and dumps the contents of the attachment into an existing mySQL table.
I already know about using ".forward' containing "|/my path", it's just the script itself I need.
The incoming emails of concern will have an attachment. The name of the attachment is important. The name of the attachment will be in the form:
ABCDEF_20080412_12345 and contains ASCII text. The ASCII text is in CSV format.? The only important part of the attachment name is the "ABCDEF" part. This is a variable length prefix (usually 4 to 6 characters)? , but this means the underscore will have to be exploded rather than a fixed number of characters used.
At the top of the script? I will need? some type of? array to list the "allowed" values for the email attachment name. If the extracted attachment name prefix (ABCDEF etc) is not in the allowed list, then the email and attachment must not be processed. Also, if there is no attachment, the email should? not be processed through the rest of the script as this will probably be spam email.
Once the prefix of the name of the attachment (ABCDEF etc) is found and validated, this prefix plus an extra comma (,)? needs to be appended to the beginning of every line of the attachment before it is written into the mySQL database/table.
The following variables will need to be declared at the top of the PHP so I can edit them:
$db_host = "localhost";
$db_name = "xxxxx";
$db_usr = "yyyyyy";
$db_pwd = "zzzzzz";
$db_table = "alt_text";
The variable $db_table name is the name of the table to finally write the data into. The data needs to be written in "append" form, so that any existing data in the table remains unaffected.
So here's an example:
If an email arrives with an attachment named [url removed, login to view] and TEST is an allowed prefix and the attachment? contains the following data:
APPLE,20080411,56.15,57.48,56.07,56.19,1500800
ORANGE,20080411,22.19,22.82,22.12,22.64,41100
PEAR,20080411,28.08,28.08,27.13,27.28,915200
...then the following will be written into the table called "alt_text":
TEST,APPLE,20080411,56.15,57.48,56.07,56.19,1500800
TEST,ORANGE,20080411,22.19,22.82,22.12,22.64,41100
TEST,PEAR,20080411,28.08,28.08,27.13,27.28,915200
....
....
etc...
There can be anything from a few dozen to several thousand lines in the attachment.
If you have any questions, drop me an email and I'll reply as soon as I can.
Project ID: #3864534