I have a form for that a user fills out and submits. Once submitted The form needs to create a doc from the input, attach the doc to an email with the mail() function and email it to the person I specify.
Currently I am creating the doc file this way:
HEADER("Content-Type: application/vnd.ms-word; name='word'");
HEADER("Content-type: application/octet-stream");
HEADER("Content-Disposition: attachment; filename=filename_here.doc");
HEADER("Cache-Control: must-revalidate, post-check=0, pre-check=0");
HEADER("Pragma: no-cache");
HEADER("Expires: 0");
ECHO $header."\n".$body;
EXIT;
Obviously this outputs the document. I want to attach it to an email since I don't want the user to get the document. The user will be redirected to a confirmation or error page depending on the situation.
Thanks!
-------------- EDIT -----------------
I have the script sending an email with an attachment now. However, the attachment is only 3k is size. This is the script I'm using to attach the data and send the email. Its the same script I use when a user provides the file. I changed the script from reading in the data from a file to base ecode the "body" directly.
$headers = "From: fromperson@email.com";
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// 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" .
$content . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($body));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: application/ms-word;\n" .
" name=\"testfile.doc\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"testfile.doc\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
// Send the message
$ok = @mail('toperson@email.com', 'test file', $message, $headers);
if ($ok)
{
echo 'yes';
} else
{
echo 'no';
}
I'm not seeing why the file is only 3k.