PDA

View Full Version : PHP email attachments problem-can't get file path



edryan
May 11th, 2009, 11:05 PM
someone, kindly please help me on this...this is my second thread, omg, and i've goggling this for days,nothing happens.just wondering why this isn't working..
can't get the path to the file..i don't know how to get the file path for the attachment.
the field for file of my form is just


<input type="file" name="file" style="float: left; border: 1px solid #FF9933" size="25" />


i also declare to my form the "enctype='multipart/form-data'"...

i got these errors after i submit the form..

Warning: fopen(file.docx) [function.fopen]: failed to open stream: No such file or directory in /home/content/b/a/i/man08/html/send_email.php on line 61

Warning: filesize() [function.filesize]: stat failed for file.docx in /home/content/b/a/i/man08/html/send_email.php on line 62

Warning: fread(): supplied argument is not a valid stream resource in /home/content/b/a/i/man08/html/sendr_email.php on line 62

Warning: fclose(): supplied argument is not a valid stream resource in /home/content/b/a/i/man08/html/send_email.php on line 63


here is the codes...
im not really sure with my "$attachment" variable..



$attachment = $_FILES['resume_file']['name'];
$fileatt = $attachment; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
$fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment
//$fileatt_name = $attachment;

$email_from = $name_from; // Who the email is from
$email_subject = $subject; // The Subject of the email
$email_txt = $body; // Message that the email has in it

$email_to = $email_to; // Who the email is to

$headers = "From: ".$email_from;

$file = fopen($fileatt,'r');
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="";

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$email_txt .= $msg_txt;

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_txt . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";


$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "Ok, sent!";
} else {
echo "Sorry, form not sent!";
}

edryan
May 12th, 2009, 12:53 AM
i got it guyz..the file should be uploaded to the server first and then get the file directory path..that's why i got those errors..hahah..now i know!

bad head... bisrockz!!!