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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to send attachment?

Status
Not open for further replies.

alan123

MIS
Joined
Oct 17, 2002
Messages
149
Location
US
I try to send email with attachment, if I use the code:
Code:
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: text/html;\n" .
              " boundary=\"{$mime_boundary}\"";
  $data = chunk_split(base64_encode($data));
  $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" .
              "--{$mime_boundary}--\n";
}

$message = StripSlashes($message);
mail($to, $subject, $message, $headers);

I can receive email but attatchment will be:

--==Multipart_Boundary_x72b635c7702060d0b1fe1290622e371ex Content-Type: application/x-zip-compressed; name="test.zip" Content-Transfer-Encoding: base64 UEsDBBQAAAAIAK5dgjB7/2sdbgAAAIEAAAAIAAAAdGVzdC5ydGYlyzEOgzAMBdDOSNyBIzihnZi4 hxc3ianVKEWxCwPi7gW6PH19/b9hNXZIReUizJPzD48xMcNppjI56PsN+VPMnvkIgKyrqCKHF1VN Bt1YhfKw722Di6T1LSXe8RsczlTj/+Ghs6R2cdZtc6xvP1BLAQIUABQAAAAIAK5dgjB7/2sdbgAA AIEAAAAIAAAAAAAAAAEAIAC2gQAAAAB0ZXN0LnJ0ZlBLBQYAAAAAAQABADYAAACUAAAAAAA= --==Multipart_Boundary_x72b635c7702060d0b1fe1290622e371ex--

If I change the headers from:
Code:
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: text/html;\n" .
              " boundary=\"{$mime_boundary}\"";
to
Code:
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";

I can receive attachment correctly but lose the email contents.
How can I receive both email body and attachment? thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top