Why is my email function truncating my attachments?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Why is my email function truncating my attachments?

Post by joshmaker »

I am attempting to email a text file comprised of a list of variables separated by commas. However, the version of the file that is attached to my email has had the begging of the list erased.

For example, a file that contained:
customer number, email@email.com, reference information, 11 x 14, New York"," NY, 23/12/2006, Metro
resulted in an attachment equal to:
11 x 14, New York"," NY, 23/12/2006, Metro
Here is my code:

Code: Select all

$fp = fopen($file,"r");
		$fcontent = fread($fp ,filesize($file));
		fclose($fp);
		$content = chunk_split(base64_encode($fcontent));
		$boundary = strtoupper(md5(uniqid()));
		$name = basename($file);
		$header = "From: $from\nReply-To: $from\r\n";
		$header .= "MIME-Version: 1.0\r\n";
		$header .= "Content-Type: multipart/mixed; boundary=$boundary\r\n";
		$body .= "--$boundary\r\n";
		$body .= "Content-Type: text/plain\r\n";
		$body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
		$body .= "$msgtext\r\n\r\n";
		$body .= "--$boundary\r\n";
		$body .= "Content-Type: text/plain; name=\"$file\"\r\n";
		$body .= "Content-Transfer-Encoding: base64\r\n";
		$body .= "Content-Disposition: attachment; filename=
		\"partner.txt
		\"\r\n";
		$body .= "$content\r\n";
		$body .= "--$boundary--";
If anyone could help, I would be very grateful!
joshmaker
Forum Commoner
Posts: 25
Joined: Mon May 15, 2006 2:53 pm
Location: Arlington VA

Post by joshmaker »

I still haven't figured out why this isn't working correctly, so here is a little more information:

Here is the original text file:
42, email@email.com, This is a test order, 11 x 14 black metal frame, Harrisonburg, Virginia, 05/03/2005, city with low mountains, a headline message, a caption message, This field is for special instructions, 2, Homer, Simpson, 742 Evergreen Terrace, , Springfield, ?, 29981, 555-555-5555, homer@simpson.com
Here is the content of the email attachment:
metal frame, Harrisonburg, Virginia, 05/03/2005, city with low mountains, a headline message, a caption message, This field is for special instructions, 2, Homer, Simpson, 742 Evergreen Terrace, , Springfield, ?, 29981, 555-555-5555, homer@simpson.com
As you can see, the first 56 characters have been lost, and I don't know why!

The header looks like this:
From: email@email.com Reply-To: email@email.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=D41D8CD98F00B204E9800998ECF8427E
And the body looks like this:
--D41D8CD98F00B204E9800998ECF8427E Content-Type: text/plain Content-Transfer-Encoding: 8bit Indigo Night Partner #42 (email@email.com) has ordered 2 11 x 14 black metal frame print Reference Information: This is a test order The Night Sky over Harrisonburg, Virginia on 03-05-2005 Headline: a headline message Caption: a caption message Special Instructions: This field is for special instructions This print should be delivered to: Homer Simpson 742 Evergreen Terrace Springfield, ?, 29981 --D41D8CD98F00B204E9800998ECF8427E Content-Type: text/plain; name="csv/42_1148058347.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename= "partner.txt " NDIsIGVtYWlsQGVtYWlsLmNvbSwgVGhpcyBpcyBhIHRlc3Qgb3JkZXIsIDExIHggMTQgYmxhY2sg bWV0YWwgZnJhbWUsIEhhcnJpc29uYnVyZywgVmlyZ2luaWEsIDA1LzAzLzIwMDUsICBjaXR5IHdp dGggbG93IG1vdW50YWlucywgYSBoZWFkbGluZSBtZXNzYWdlLCBhIGNhcHRpb24gbWVzc2FnZSwg VGhpcyBmaWVsZCBpcyBmb3Igc3BlY2lhbCBpbnN0cnVjdGlvbnMsIDIsIEhvbWVyLCBTaW1wc29u LCA3NDIgRXZlcmdyZWVuIFRlcnJhY2UsICwgU3ByaW5nZmllbGQsID8sIDI5OTgxLCA1NTUtNTU1 LTU1NTUsIGhvbWVyQHNpbXBzb24uY29t --D41D8CD98F00B204E9800998ECF8427E--
If anyone could point me in the correct direction, I would be very greatful!
Post Reply