FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problem with attaching file (from a form) to email in PHP
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
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 Go to previous messageGo to previous message
Cameleon is currently offline  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);
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SOCIAL NETWORK FOR PHP PLATFORM..
Next Topic: HTML select field where the OPTION text is of different colors
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 19:51:43 GMT 2024

Total time taken to generate the page: 0.05067 seconds