Thanks Izzy for your response, and I be's a workin' on it, but thanks to my extremely limited web experience, nearly everything I read provides more questions than answers, and I can't figure out where to look for more answers. I think his explanations presume much more knowledge & experience than I currently have.
Conceptually, I could follow the tutorial - more or less (mostly less) - and I downloaded the test script, but much of the code detail, I couldn't understand. The test script worked with a form that's included in the download so here are some of my confusions:
- Code: Select all
// Read POST request params into global vars
$to = $_POST['to'];
$from = $_POST['from'];
$subject = $_POST['subject'];
$message = $_POST['message'];
This part is fine; I've done that throughout my pages. The next segment, however, poses questions:
- Code: Select all
// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
I'm not sure if this is necessary in my case since the .pdf's are generated from my pages using a product called FPDF. It allows the .pdf's to be sent to; the browser, a local file (on the server), download them or return them as strings. Currently, for testing purposes, I'm sending them to the browser, but for the final product, I'm not sure which w/b the best to use.
Next confusion;
- Code: Select all
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
What is a boundary string, and would I just use this as is or will it be necessary to modify it for my use? If so, how/what?
Now, more questions
- Code: Select all
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
Do I ALWAYS just use this as is? Is the version ALWAYS 1.0?
Next segment:
- Code: Select all
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
I sort of think that the above would be used more or less as is (even though I don't understand the meaning of the values - even the comment is confusing to me), except maybe for the text in the first line. What I'm curious about is the last line. It looks like he's adding lines 2 - 4, then appending the value of the variable itself. I do that when I want to add data at the beginning of a variable that already has a value assigned, but I don't see anywhere above that segment where $message is being assigned a value.
Next is:
- Code: Select all
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
Would I need this at all, since my attachment(s) is/are .pdf and not binary?
Then finally:
- Code: Select all
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
Won't this replace the values previously loaded into $message? Why are those two lines commented out, and will they be included in the value of $message? If I don't use the "$dat = ..." segment, would I leave out the next-to-last line above, or replace it with something else, and if so, what?
I realize this is asking a lot, but If you could enlighten me about this, I'd be very grateful. I'm getting dangerously close to my deadlines and this is the only part of my project that isn't working.