下一页有效,但提交时我没有收到邮件的文件。
到达的邮件:
MIME-Version:1.0 内容类型:multipart / mixed; 边界= “== Multipart_Boundary_xa18882382b8d92109533240902ace32ex”
- == Multipart_Boundary_xa18882382b8d92109533240902ace32ex 内容类型:text / plain;字符集= “ISO-8859-1” 内容传输编码:7位
...之后是来自输入的价值($ msg)
......然后
- == Multipart_Boundary_xa18882382b8d92109533240902ace32ex
**没有文件
<?php
if(isset($_FILES) && (bool) $_FILES) {
$allowedExtensions = array("pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt");
$files = array();
foreach($_FILES as $name=>$file) {
$file_name = $file['name'];
$temp_name = $file['tmp_name'];
$path_parts = pathinfo($file_name);
$ext = $path_parts['extension'];
if(!in_array($ext,$allowedExtensions)) {
die("File extensions not allowed");
}
$server_file = "/tmp/$path_parts[basename]";
move_uploaded_file($temp_name,$server_file);
array_push($files,$server_file);
}
$mail_to = 'dorozenman@gmail.com'; // specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$suname = $_POST['sender_suname'];
$Bday = $_POST['sender_Bday'];
$nowWork = $_POST['sender_work'];
$phone = $_POST['sender_phone'];
$mail_from = $_POST['sender_email'];
$free = $_POST['sender_way'];
// Construct email headers
$headers = 'From: ' . $mail_from . "\r\n";
// Construct email subject
$subject = 'בקשה לרעיון עבודה' . $name;
// Construct email body
$msg = 'name: ' . $name . "\r\n";
$msg .= 'suname: ' . $suname . "\r\n";
$msg .= 'Bday: ' . $Bday . "\r\n";
$msg .= 'nowWork: ' . $nowWork . "\r\n";
$msg .= 'phone: ' . $phone . "\r\n";
$msg .= 'mail_from: ' . $mail_from . "\r\n";
$msg .= 'free: ' . $free;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
$message ="\n\n--{$mime_boundary}\n";
$message .="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .="Content-Transfer-Encoding: 7bit\n\n" . $msg . "\n\n";
$message .= "--{$mime_boundary}\n";
foreach($files as $file) {
$aFile = fopen($file,"rb");
$data = fread($aFile,filesize($file));
fclose($aFile);
$data = chunk_split(base64_encode($data));
$massage .= "Content-Type: {\"application/octet-stream\"};\n";
$massage .= " name=\"$file\"\n";
$massage .= "Content-Disposition: attachment;\n";
$massage .= " filename=\"$file\"\n";
$massage .= "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$massage .= "--{$mime_boundary}\n";
}
$mail_sent = mail($mail_to, $subject, $message, $headers);
if ($mail_sent){ ?>
<script language="javascript" type="text/javascript">
alert('yay');
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('nay');
</script>
<?php
}
}
?>
怎么了?如果我没有从页面收到任何php警告,为什么我没有收到文件?
答案 0 :(得分:1)
您在if语句中将$ _FILES(数组)类型转换为bool。你应该写is_array($ _ FILES)而不是(bool)$ _FILES,然后你应该得到你的文件。