Jump to content

mail attachment nightmare


dennismonsewicz

Recommended Posts

here is the code I am using:

 

$fileatt = $file; // Path to the file
				$fileatt_type = "application/octet-stream"; // File Type
				$fileatt_name = "filename.xls"; // Filename that will be used for the file as the attachment

				$email_from = "me@me.com"; // Who the email is from
				$email_subject = "subject here"; // The Subject of the email
				$email_message = "This is a test"; // Message that the email has in it

				$email_to = "me@me.com"; // Who the email is too

				$headers = "From: ".$email_from;



				$semi_rand = md5(time());
				$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

				$headers .= "\nMIME-Version: 1.0\n" .
				"Content-Type: multipart/mixed;\n" .
				" boundary=\"{$mime_boundary}\"";

				$email_message .= "This is a multi-part message in MIME format.\n\n" .
				"--{$mime_boundary}\n" .
				"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
				"Content-Transfer-Encoding: 7bit\n\n" .
				$email_message . "\n\n";

				$attached_file = fopen($fileatt,'rb');
				$data = fread($attached_file,filesize($fileatt));
				fclose($attached_file);


				$data = chunk_split(base64_encode($data));

				$email_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";
				unset($data);
				unset($attached_file);
				unset($fileatt);
				unset($fileatt_type);
				unset($fileatt_name);

				$ok = @mail($email_to, $email_subject, $email_message, $headers);

				if($ok) {
				echo "The file was successfully sent!";
				} else {
				die("Sorry but the email could not be sent. Please go back and try again!");
				}

 

The email I receive has a bunch of coded jumbly goop with no attachment...

 

Email attachment:

This is a testThis is a multi-part message in MIME format.

--==Multipart_Boundary_x4db218f24afded124fee220fcb9d6110x
Content-Type:text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

This is a test

--==Multipart_Boundary_x4db218f24afded124fee220fcb9d6110x
Content-Type: application/octet-stream;
name="filename.xls"
Content-Transf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4=


--==Multipart_Boundary_x4db218f24afded124fee220fcb9d6110x

-------

 

I have no idea what could be wrong

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.