Re: Problem with attaching file (from a form) to email in PHP [message #172699 is a reply to message #172668] |
Sat, 26 February 2011 14:56 |
Cameleon
Messages: 7 Registered: February 2011
Karma:
|
Junior Member |
|
|
Sorry about that.. was so stuck in my problem that I forgot to say
what it was.
I've continued working on it, and managed to make it work... half.
I've rewrote the code, and now I'm able to successfully send the
email, but I can only see the attachment when using gmail. If I red
the message using the Mac "Mail" program, there is no trace of the
attachment (neither as attached file, neither inline in the message
body), and if I read it using MS Outlook, The attachment is there with
the proper file size, but when I try to read it, it says No preview
available or file is empty. Also, interresting thing is that if I
take the message that I received in gmail, and forward it using gmail,
I can now read it properly with both Mail and Outlook.
I kind of highly suspect that there is a problem with the heder or
something like this, but can't see waht.
Thanks for your help, here is the parts of the code that deals with
the sending...
// ATTACHENMENT INFOS
$UploadedFile_name = $_FILES["UploadedFile"]["name"];
$UploadedFile_type = $_FILES["UploadedFile"]["type"];
$UploadedFile_size = $_FILES["UploadedFile"]["size"];
$UploadedFile_temp = $_FILES["UploadedFile"]["tmp_name"];
// MAIL SUBJECT
$subject = $_POST['Sujet'] . " from website";
$subject = str_replace("\'", "'", $subject);
// MAIL ADDRESSES
$to = "Webmaster <Master(at)Website(dot)com>";
$name = str_replace("'", "''", $_POST['Name']);
$From = $name . " <" . $_POST['Email'] . ">";
//Initial Headers
$boundary = md5(date('r', time()));
$headers = "From: ".$From."\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=" . $boundary .
"\r\n";
$headers .= "MIME-Version: 1.0\r\n";
//First Content Type (TXT)
$message = "\r\n\r\n--" . $boundary . "\r\n"; // MAKE SURE there's
only ONE(1) "\r\n" between the above boundry and the first header
below (Content-Type)
$message .= "Content-Transfer-Encoding: quoted-printable\r\n";
$message .= "Content-type: text/plain; charset=\"UTF-8\"\r\n\r\n";
$message .= $MsgTXT;
If ($UploadedFile_name != "" ) {
//Second Content Type (ATTACHEMENT)
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Disposition: in-line; filename=
$UploadedFile_name\r\n";
$message .= "Content-type: ".$UploadedFile_type."; x-unix-mode=0755;
name=\"$UploadedFile_name\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= base64_encode(file_get_contents($_FILES["UploadedFile"]
["tmp_name"])); // Attachement Encoding
$message .= "\r\n\r\n--" . $boundary . "--"; // <- This indicates
the end of the boundries. Notice the additional "--" after the
boundry's value.
}
// Send the email using "mail()".
$MailSent = @mail($to, $subject, $message, $headers);
|
|
|