Hi,
I've used a code for sending e-mail via mail() function which posted here a programmer "ignition" (thread434-153872).
This code succesfully send an e-mail message which (in Outlook) contains some attachments (jpg image in this case).
But, the image has only a few of bytes and it's not an image at all. Whats wrong?
Here is the code I use:
*****************************************************************
$mail_to = "me@localhost";
$mail_from = "from@someone.com";
$mail_body_orig1 = "some body text";
$mail_title = "some subject";
$file_name_type = "image/jpeg";
$mail_boundary = md5(uniqid(time()));
$mail_headers .= "From: $mail_from \n";
$mail_headers .= "MIME-Version: 1.0\r\n";
$mail_headers .= "Content-type: multipart/mixed;";
$mail_headers .= "boundary= \"$mail_boundary\"";
$mail_headers .= "\r\n\r\n";
$new_mail_body .= "--$mail_boundary\n";
$new_mail_body .= "Content-type: text/plain; charset=us-ascii\r\n";
$new_mail_body .= "Content-transfer-encoding: quoted-printable\r\n\r\n";
$new_mail_body .= $mail_body_orig1;
$new_mail_body .= "\r\n";
$new_mail_body .= $file_name;
$new_mail_body .= "\r\n";
$new_mail_body .= "--$mail_boundary\n";
$mime_type = $file_name_type;
$new_mail_body .= "Content-type:$mime_type; name=\"$file_name\"\r\n";
$new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$new_mail_body .= "Content-Disposition: attachment; filename=".$file_name."\"\r\n";
$new_mail_body .= chunk_split(base64_encode($file_name))."\r\n";
$new_mail_body .= "\r\n\r\n";
$new_mail_body .= "--$mail_boundary--";
mail($mail_to , $mail_title, $new_mail_body, $mail_headers);
*****************************************************************
... and I attach the source of message (Outlook XP) ...
*****************************************************************
Received: from [127.0.0.1] by cuckoo
(ArGoSoft Mail Server, Version 1.8 (1.8.1.2)); Thu, 26 Sep 2002 21:57:26 +0200
Date: Thu, 26 Sep 2002 21:57:25 +0100
Subject: some subject
To: me@localhost
From: from@someone.com
MIME-Version: 1.0
Content-type: multipart/mixed;boundary= "7019ce4f7c116f0e65ac1679169599d6"
Message-ID: <ug14kmj8a34wk8i.260920022157@cuckoo>
--7019ce4f7c116f0e65ac1679169599d6
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: quoted-printable
some body text
Jakub.jpg
--7019ce4f7c116f0e65ac1679169599d6
Content-type:image/jpeg; name="Jakub.jpg"
Content-transfer-encoding:base64
Content-Disposition: attachment; filename=Jakub.jpg"
SmFrdWIuanBn
--7019ce4f7c116f0e65ac1679169599d6--
*****************************************************************
If someone could give me a hint, I'll be gratefull
Gany
I've used a code for sending e-mail via mail() function which posted here a programmer "ignition" (thread434-153872).
This code succesfully send an e-mail message which (in Outlook) contains some attachments (jpg image in this case).
But, the image has only a few of bytes and it's not an image at all. Whats wrong?
Here is the code I use:
*****************************************************************
$mail_to = "me@localhost";
$mail_from = "from@someone.com";
$mail_body_orig1 = "some body text";
$mail_title = "some subject";
$file_name_type = "image/jpeg";
$mail_boundary = md5(uniqid(time()));
$mail_headers .= "From: $mail_from \n";
$mail_headers .= "MIME-Version: 1.0\r\n";
$mail_headers .= "Content-type: multipart/mixed;";
$mail_headers .= "boundary= \"$mail_boundary\"";
$mail_headers .= "\r\n\r\n";
$new_mail_body .= "--$mail_boundary\n";
$new_mail_body .= "Content-type: text/plain; charset=us-ascii\r\n";
$new_mail_body .= "Content-transfer-encoding: quoted-printable\r\n\r\n";
$new_mail_body .= $mail_body_orig1;
$new_mail_body .= "\r\n";
$new_mail_body .= $file_name;
$new_mail_body .= "\r\n";
$new_mail_body .= "--$mail_boundary\n";
$mime_type = $file_name_type;
$new_mail_body .= "Content-type:$mime_type; name=\"$file_name\"\r\n";
$new_mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$new_mail_body .= "Content-Disposition: attachment; filename=".$file_name."\"\r\n";
$new_mail_body .= chunk_split(base64_encode($file_name))."\r\n";
$new_mail_body .= "\r\n\r\n";
$new_mail_body .= "--$mail_boundary--";
mail($mail_to , $mail_title, $new_mail_body, $mail_headers);
*****************************************************************
... and I attach the source of message (Outlook XP) ...
*****************************************************************
Received: from [127.0.0.1] by cuckoo
(ArGoSoft Mail Server, Version 1.8 (1.8.1.2)); Thu, 26 Sep 2002 21:57:26 +0200
Date: Thu, 26 Sep 2002 21:57:25 +0100
Subject: some subject
To: me@localhost
From: from@someone.com
MIME-Version: 1.0
Content-type: multipart/mixed;boundary= "7019ce4f7c116f0e65ac1679169599d6"
Message-ID: <ug14kmj8a34wk8i.260920022157@cuckoo>
--7019ce4f7c116f0e65ac1679169599d6
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: quoted-printable
some body text
Jakub.jpg
--7019ce4f7c116f0e65ac1679169599d6
Content-type:image/jpeg; name="Jakub.jpg"
Content-transfer-encoding:base64
Content-Disposition: attachment; filename=Jakub.jpg"
SmFrdWIuanBn
--7019ce4f7c116f0e65ac1679169599d6--
*****************************************************************
If someone could give me a hint, I'll be gratefull
Gany