-1
我有一個帶有文件上傳的表單。表單提交後,應該通過電子郵件發送文件。我正在使用一個簡單的PHP腳本,但它不起作用。將上傳的文件作爲電子郵件附件發送
如何通過電子郵件發送上傳的文件?
//Send Mail
$file_tmp_name = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$boundary = md5("sanwebe");
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$mail."\r\n";
$headers .= "Reply-To: ".$mail."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = ".$boundary."\r\n\r\n";
//plain text
$body = "--".$boundary."\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message));
//attachment
$body .= "--".$boundary."\r\n";
$body .="Content-Type: ".$file_type."; name=".$file_name."\r\n";
$body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
send_mail($to,$subject,$body,$headers);
是的我有enctype – Siddhu