0
안녕하십니까,첨부 파일을 추가 할 수 없습니다.
이메일에 첨부 파일을 보낼 수 없습니다. 웹 사이트에서 보낼 수 있지만 첨부 파일은 보입니다. 보내는 전자 메일에 첨부 파일을 어떻게 추가 할 수 있습니까?
--451b4ac97a84a2205e1d116ef096f765 의 Content-Type : 내가 좋아하는 텍스트를 참조 할 "이미지/JPEG를, 이름 ="testbeeld.jpg " 내용 - 처리 : 첨부 파일, 파일 이름 ="testbeeld.jpg " 내용-은 Transfer- 인코딩 : base64로 X-첨부 ID :.. 내 몸에서 66,045
그것으로 모양을내어 감사
if($_POST && isset($_FILES['File_upload']))
{
$recipient_email = $_POST['email2']; //recepient
$from_email = $_POST['email']; //from email using site domain.
$subject = $_POST['title']; //email subject line
$sender_email = filter_var($_POST["email"], FILTER_SANITIZE_STRING); //capture sender email
$sender_message = filter_var($_POST['message'], FILTER_SANITIZE_STRING); //capture message
$attachments = $_FILES['File_upload'];
$file_count = count($attachments['name']); //count total files attached
$boundary = md5("keukenaanbod.nl");
if($file_count > 0){ //if attachment exists
//header
$headers = 'MIME-Version: 1.0\r\n'.
'From: [email protected]' . "\r\n".
'Reply-To: ' . $sender_email . '' . "\r\n" .
'Cc: ' . $sender_email . '' . "\r\n" .
'X-Mailer: PHP/' . phpversion().
'Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n';
//message text
$body .= "Er is gereageerd op jouw keuken aanvraag, reageer op deze mail om in contact te komen:\r\n\"" . $sender_message . "\"\r\n\r\n\r\n";
//attachments
for ($x = 0; $x < $file_count; $x++){
if(!empty($attachments['name'][$x])){
if($attachments['error'][$x]>0) //exit script and output error if we encounter any
{
$mymsg = array(
1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
3=>"The uploaded file was only partially uploaded",
4=>"No file was uploaded",
6=>"Missing a temporary folder");
die($mymsg[$attachments['error'][$x]]);
}
//get file info
$file_name = $attachments['name'][$x];
$file_size = $attachments['size'][$x];
$file_type = $attachments['type'][$x];
//read file
$handle = fopen($attachments['tmp_name'][$x], "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content)); //split into smaller chunks (RFC 2045)
$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;
}
}
}else{ //send plain email otherwise
$headers = "MIME-Version: 1.0" . "\r\n".
"Content-type:text/html;charset=UTF-8" . "\r\n".
'From: [email protected]' . "\r\n".
'Reply-To: ' . $sender_email . '' . "\r\n" .
'Cc: ' . $sender_email . '' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = $sender_message;
}
$sentMail = @mail($recipient_email, $subject, $body, $headers);
if($sentMail) //output success or failure messages
{
header('Location: /verzenden-gelukt?id='. $id .'');
}else{
die('Email kon helaas niet verzonden worden, u dient direct uit te zoeken wat er gaande is!');
}
}
}
phpmailer가 훨씬 더 쉽게 사용할 수 있습니다. –
예,하지만 phpmailer를 사용하고 싶지는 않습니다. 이것은 이전에 효과가 있었고, 뭔가 바뀌었고 무엇을 알아야합니다. –
http://stackoverflow.com/questions/12301358/send-attachments-with-php-mail 3 초 구글에서 ;-) –