2016-10-20 5 views
1

텍스트 메일은 정상적으로 작동하지만 파일도 첨부하고 싶습니다. 첨부 파일이 작동하지 않습니다. 내 코드는 다음 코드를 작동하지만 파일 위첨부 파일이 메일 기능 WordPress에서 작동하지 않습니다

<form method="post" enctype="multipart/form-data"> 
    <input name="filepc" type="file" id="filepc" class="listEm" /> 
</form> 


if (isset($_POST['submit'])) { 
    $attachments = ''; 
    if (!empty($_FILES['filepc']['tmp_name'])) { 
     $attachments = array($_FILES['filepc']['name']); 

    } 

headers = "From:" . $your_email . " < " . $email . ">" . "\r\n"; 
     $headers .= "Reply - To:" . $ct_email . "\r\n"; 
     $headers .= "Content-Disposition: attachment; filename=\"".$attachments."\"\r\n\r\n"; 
     //$headers = "Bcc: [email protected] . com" . "\r\n"; 
     $headers = "X - Mailer: PHP/" . phpversion(); 
     mail($to , $subject , $msg , $headers,$attachments); 
$successMsg = '<h5 style="color:red;">Sent successfully</h5>'; 
//  } 

} 

가 연결되어 있지 않습니다. 이 문제에 대한 해결책을 찾도록 도와주세요.

답변

1
if(!empty($_FILES['resume']['name'])) { 
    $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; 
    $tmp_name = $_FILES['resume']['tmp_name']; 
    $type = $_FILES['resume']['type']; 
    $file_name = $_FILES['resume']['name']; 
    $size = $_FILES['resume']['size']; 

    // Check to make sure that it is an uploaded file and not a system file 
    if(is_uploaded_file($tmp_name)){ 
     // Now Open the file for a binary read 
     $file = fopen($tmp_name,'rb'); 
     // Now read the file content into a variable 
     $data = fread($file,filesize($tmp_name)); 
     // close the file 
     fclose($file); 
     // Now we need to encode it and split it into acceptable length lines 
     $data = chunk_split(base64_encode($data)); 
    } 
    $mybody = "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" . 
    $mybody . "\n\n"; 

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

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

    $bodys .= "$mybody <br>"; 
    $subject = "Attachment"; 
    $body = $body . $bodys; 
    mail($to, $subject, $body, $headers); 
} 
+0

$ msg = "\ n \ n" "전화 : $ 제목". "\ n". "이름 : $ first_name" "\ n". "성 : $ last_name" "\ n". "첨부 파일 : echo '이미지 : ';" . "\ n". "연락 할 선호 모드 : $ prmode". "\엔"; 첨부 파일이있는 전자 메일에이 메시지를 추가하는 방법 – user2851129

+0

여러 첨부 파일을 사용하는 방법 – user2851129

+0

나는 그것을 수행했습니다. tq – user2851129

관련 문제