Help with MIME Attachments
Posted: Mon Nov 07, 2005 4:14 pm
Good afternoon, everyone. I have written some code to create an e-mail with an attachment, but I must be missing something somewhere. Hopefully some wise person here will immediately see my mistake!
The prog successfully creates and sends the e-mail, including the attachment, but the contents of the attachment are hacked up. Attaching a very short text file, only the last few characters survive. Attaching a larger (5K) text file, I receive nothing. Attaching a DOC or PDF, the contents are corrupted but the file size is about right.
I believe my MIME is correct. Outlook understands which application to open the attachment with. Unfortunately Outlook does not show all the headers, but if it would be useful I can redirect my output to a file and post it.
One oddity that could possibly relate: file_size won't run on $_FILES['Resume']['tmp_name']. I've been trying variations on this theme and browsing docs and Google, no luck so far.
Any ideas? Thanks!
The prog successfully creates and sends the e-mail, including the attachment, but the contents of the attachment are hacked up. Attaching a very short text file, only the last few characters survive. Attaching a larger (5K) text file, I receive nothing. Attaching a DOC or PDF, the contents are corrupted but the file size is about right.
I believe my MIME is correct. Outlook understands which application to open the attachment with. Unfortunately Outlook does not show all the headers, but if it would be useful I can redirect my output to a file and post it.
Code: Select all
$Headers = "MIME-Version: 1.0\r\nContent-type: multipart/mixed; boundary=\"NEXTMIMEPART\"\r\n";
$Message = "This is a MIME multi-part e-mail. You need to upgrade your e-mail client.\r\n";
$Message .= "--NEXTMIMEPART\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: 7bit\r\n";
... Adds HTML part of message...
... Checks if an attachment was included, verifies the type, etc...
$Message .= "--NEXTMIMEPART\r\nContent-Type: {$_FILES['Resume']['type']}; name=\"{$_FILES['Resume']['name']}\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment\r\n";
$ResumeFile = fopen($_FILES['Resume']['tmp_name'], "rb");
...Confirms file opened OK...
$Message .= "\"" . chunk_split(base64_encode(addslashes(fread($ResumeFile, 1024000))), 76, "\r\n") . "\"\r\n";
$Message .= "--NEXTMIMEPART--\r\n";
return mail("Admin@TMSContracting.com", $Title, $Message, $Headers);Any ideas? Thanks!