hi,
I m using the following code to attach a file in an email and sending it through the
mail function.
but the problem i face is that that mail is sent but there is not attachment in it , i
have tried it lots of times
but didn't find the actuall cause of this logical error.
the server is Apache Server and the Linux Plateform.
file_upload is set to on ,
max file size is allright,
but still the problem...
here s the code
/////////////////////////////////////
function send_mail($vars){
global $send_to, $send_cc;
global $subject;
global $attachment_enabled;
global $REMOTE_ADDR;
global $HTTP_POST_FILES;
//$vars['subject']="ÇáÚÇãÉ";
$files = array(); //files (field names) to attach in mail
if (count($HTTP_POST_FILES) && $attachment_enabled){
$files = array_keys($HTTP_POST_FILES);
}
// build mail
$date_time = date('Y-m-d H:i:s');
$mime_delimiter = md5(time());
$fields = _build_fields($vars);
$mail =<<<EOF
This is a MIME-encapsulated message
--$mime_delimiter
Content-type: text/plain;
charset: windows-1256
Content-Transfer-Encoding: 8bit
$fields
--------------------
EOF;
// i guess the problem is in the following code
if (count($files)){
foreach ($files as $file)
{
$file_name = $HTTP_POST_FILES[$file]['name'];
$file_type = $HTTP_POST_FILES[$file]['type'];
$file_tmp_name = $HTTP_POST_FILES[$file]['tmp_name'];
$file_cnt = "";
$f=@fopen($file_tmp_name, "rb");
if (!$f)
continue;
while($f && !feof($f))
$file_cnt .= fread($f, 4096);
fclose($f);
if (!strlen($file_type)) $file_type="applicaton/octet-stream";
if ($file_type == 'application/x-msdownload')
$file_type = "applicaton/octet-stream";
$mail .= "\n--$mime_delimiter\n";
$mail .= "Content-type: $file_type\n";
$mail .= "Content-Disposition: attachment; filename=\"$file_name\"\n";
$mail .= "Content-Transfer-Encoding: base64\n\n";
$mail .= chunk_split(base64_encode($file_cnt));
}
}
$mail .= "\n--$mime_delimiter--";
//send to
// $_send_to = $send_to ? $send_to : "$vars[name_to] <".$vars["email_to"].">";
$_send_from = "$vars[name_from] <".$vars["email_from"].">";
$_subject = $subject ? $subject : $vars['subject'];
//$a=intval($vars['email']);
$_send_to=$send_to;
mail($_send_to, $_subject, $mail, "Mime-Version: 1.0\nFrom:
$_send_from\nContent-Type: multipart/mixed;\n
boundary=\"$mime_delimiter\"\nContent-Disposition: inline");
*/
}
/////////////////////////////////////
---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now