Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail with attachments problem 1

Status
Not open for further replies.

speedyrudolf

Programmer
Sep 2, 2009
27
RO
Hi. I have the following code:
Code:
else if(file_exists("site".$timp.".zip"))
	{$file=fopen("site".$timp.".zip", "rb");
	$data=fread($file, filesize("site".$timp.".zip"));
	fclose($file);
	$data=chunk_split(base64_encode($data));
	$message.="Content-Type:{\"application/octet-stream\"};\n"."name=
\"site".$timp.".zip\"\n"."Content-Disposition: attachment;\n"."filename=
\"site".$timp.".zip\"\n"."Content-Transfer-Encoding: base64\n\n".$data."
\n\n";
	$message.="--{{$mime_boundary}\n";
	unset($data);
	unset($file);
	if(mail($to, $subject, $message, $headers))
		{header("Location: comanda_primita.html");}
The problem with it is, there is no attachment. Instead, at the end of the mail I get:

--==Multipart_Boundary_x1074db4782f70d7323f462617b73ab9dx
Content-Type:{"application/octet-stream"};
name="site1256892830.zip"
Content-Disposition: attachment;
filename="site1256892830.zip"
Content-Transfer-Encoding: base64

UEsHCFBLAwQUAAAACAC5Vl47UnvYAEYJAACNUgAAFAAAADEyNTY4OTI4MzB1cGxvYWQucGhw
7Rtr
b9w28vMGyH/QCQayRrIbr5M0qR0l9ebWhQHbCWpfcLnaEGgt18urXpW4iV3D//2GD2lJkdL6dYe0
x7RxreHMcGY4Lz769n0+zx8/KvDvC1Lgvh/FqCyHGJWXf5B8CGP++vbjR2uUJHkAP3Cff8JYkOJv
3gTw/rX3CUCzrMAomvfXwt29/cmRh0pvbUZKgov1x496V2TWJ2W4yOMMTfE0nJEY9+X4r09okocp
SvCT03WG3LtayxGdB3zSYY0lMLYZQpJ9xauZPfM4n3VOwkQevEPT6S7HFgPX10KXwbsyjwnl
Q35J
KPaHYnJ/CKP+M+/VBv8jTJEFfpljPL0Mi8U0i2c/XaJ5lg2jLPHZ+KzIksD/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5Vl47UnvY
AEYJ
AACNUgAAFAAAAAAAAAAAACAAAAAEAAAAMTI1Njg5MjgzMHVwbG9hZC5waHBQSwECAAAUAAAA
CAC5
Vl47pKJIyu4JAAAkJQAAGwAAAAAAAAAAACAAAACICQAAMTI1Njg5MjgzMGNsYXNzLmVhc3l6
aXAu
cGhwUEsFBgAAAAACAAIAiwAAALsTAAAiAENvbXByZXNzZWQvU3BsaXR0ZWQgYnkgUEhQIEVh
c3la
SVA=


--{==Multipart_Boundary_x1074db4782f70d7323f462617b73ab9dx

Does anyone know what's wrong with the code? Thank you in advance.

PS: This script also sends multiple attachments (if there are multiple files)...But since it doesn't send even one attachment....
 
the easiest way to send attachments by mail is to use phpmailer.

on your code it does not look like you have closed the boundary properly. and i cannot comment on the rest of it as you have not provided the whole code snip.

remember that you need to provide a multipart/mixed header in the mail headers

and also to specify the boundary in the headers.
 
The code for the header:
Code:
$headers="From: $from";
$semi_rand=md5(time());
$mime_boundary="==Multipart_Boundary_x{$semi_rand}x";
$header.="\nMIME-Version: 1.0\n"."Content-Type: multipart/mixed;\n"."boundary=\"{$mime_boundary}\"";
And for the boundary...how should I close it? Thank you.
 
use \r\n in place of \n. some servers are picky.

and i note that line 4 is assigning the information to $header and not $header[red]s[/red]. that's probably the cause.

for closing the boundary use the same as for opening the boundary. your closing boundary seemed to have a curly brace within it.
 
Yep...That did it...Sort of...
Now the entire message is sent as an attachment, and the original attachment is in that attachment (don't really know how to describe it better). And Yahoo doesn't even see the "attachment"...But that may just be an error on their part, cause gmail sees it just fine.
Anyway...Thanks a lot...and if you help me figure this final part out...
 
i know it's nice to do these things on your own, but i really would recommend using phpmailer. i've never had a problem with it and the API is dead simple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top