YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > PHP
검색
멤버이름    오토
비밀번호 
 

메일 함수(파일전송까지)

페이지 정보

작성자 MintState 댓글 0건 조회 12,540회 작성일 08-10-29 17:19

본문

메일 함수(파일전송까지)

<?php 
function sendMail($to,$from,$title,$contents,$userfile,$userfile_name,$userfile_type,$userfile_size) { 
        // 메일을 보내기전에 필요필드에 대한 체크를 한다. 
        if(!$to) { 
                echo ("<script> 
                        window.alert('메일을 받을실분의 계정을 입력하세요!') 
                        history.go(-1) 
                        </script>"); 
                exit; 
        } 

//        if(!eregi("^[^@ ]+@[a-zA-Z0-9-.]+.+[a-zA-Z0-9-.]", $to)) { 
//                echo ("<script> 
//                        window.alert('받는사람의 E-Mail 주소형식이 틀립니다. [예] yourmail@server.domain') 
//                        history.go(-1) 
//                </script>"); 
//                exit; 
//        } 

        if(!$title) { 
                echo ("<script> 
                        window.alert('메일 제목을 입력하세요!') 
                        history.go(-1) 
                        </script>"); 
                exit; 
        } 

        // 메일의 header를 작성한다. 
        $mailheaders .= "Return-Path: $from\n"; 
        $mailheaders .= "From: $from\n"; 
        $mailheaders .= "X-Mailer: webmail\n"; 

        $boundary = "----".uniqid("part"); 

        if($userfile && $userfile_size) { 
                $filename = basename($userfile_name); 
                $fp = fopen($userfile, "r"); 
                $file = fread($fp, $userfile_size); 
                fclose($fp); 

                if($userfile_type == "") { 
                        $userfile_type = "application/octet-stream"; 
                } 

                // 헤더 파트를 작성한다. 
                // Multipart/mixed 일경우 첨부파일이 있다는 것을 의미한다. 
                $mailheaders .= "MIME-Version: 1.0\n"; 
                $mailheaders .= "Content-Type: Multipart/mixed; boundary = \"$boundary\""; 

                // 본문 파트를 작성한다. 
                $bodytext = "This is a multi-part message in MIME format.\n\n"; 
                $bodytext .= "--$boundary\n"; 
                $bodytext .= "Content-Type: text/html; charset=\"ks_c_5601-1987\"\n"; 
                $bodytext .= "Content-Transfer-Encoding: base64\n\n"; 
                $bodytext .= base64_encode(nl2br($contents))."\n\n"; 

                // 파일첨부 파트를 작성한다. 
                $bodytext .= "--$boundary\n"; 
                $bodytext .= "Content-Type: $userfile_type; name=\"$filename\"\n"; 
                $bodytext .= "Content-Transfer-Encoding: base64\n"; 
                $bodytext .= "Content-Disposition: attachment; filename=\"$filename\"\n\n"; 
                $bodytext .= base64_encode($file)."\n\n"; 

                // 멀티파트 종료를 작성한다. 
                $bodytext .= "--$boundary--"; 
        } else { 
                // 헤더 파트를 작성한다. 
                $mailheaders .= "MIME-Version: 1.0\n"; 
                $mailheaders .= "Content-Type: Multipart/alternative; boundary = \"$boundary\""; 

                // 본문 파트를 작성한다. 
                $bodytext .= "--$boundary\n"; 
                $bodytext .= "Content-Type: text/html; charset=\"ks_c_5601-1987\"\n"; 
                $bodytext .= "Content-Transfer-Encoding: base64\n\n"; 
                $bodytext .= base64_encode(nl2br($contents))."\n\n"; 

                // 멀티파트 종료를 작성한다. 
                $bodytext .= "--$boundary--\n\n"; 
        } 

        // 메일보내기에 성공하면 true, 실패하면 false를 리턴한다. 
        return mail($to, $title, $bodytext, $mailheaders); 
} 

echo "$userfile_name,$userfile_type,$userfile_size"; 
sendMail("tomail","frommail","test","asdfasdfasdfasdfasdf",$userfile,$userfile_name,$userfile_type,$userfile_size); 
?> 

댓글목록

등록된 댓글이 없습니다.

Total 165건 1 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
165 MintState 21140 10-28
164 MintState 13418 10-28
163 MintState 24122 10-28
162 MintState 13051 10-28
161 MintState 14503 10-28
160 MintState 23066 10-28
159 MintState 15914 10-28
158 MintState 12076 10-28
157 MintState 12493 10-28
156 MintState 11744 10-29
155 MintState 11649 10-29
154 MintState 12853 10-29
153 MintState 12194 10-29
152 MintState 10886 10-29
151 MintState 10988 10-29
150 MintState 9805 10-29
149 MintState 10588 10-29
열람중 MintState 12541 10-29
147 MintState 11547 10-29
146 MintState 11085 10-29
145 MintState 12267 10-29
144 MintState 14912 10-29
143 MintState 14812 10-29
142 MintState 14877 10-29
141 MintState 13441 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™