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

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

페이지 정보

작성자 MintState 댓글 0건 조회 12,516회 작성일 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건 6 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
40 MintState 12541 10-31
39 MintState 13297 10-31
38 MintState 11507 10-31
37 MintState 12993 10-31
36 MintState 13712 10-31
35 MintState 11527 10-31
34 MintState 11133 10-31
33 MintState 17924 10-31
32 MintState 14562 10-31
31 MintState 11789 10-31
30 MintState 13593 10-29
29 MintState 17911 10-29
28 MintState 12282 10-29
27 MintState 10484 10-29
26 MintState 16407 10-29
25 MintState 13405 10-29
24 MintState 14848 10-29
23 MintState 14793 10-29
22 MintState 14887 10-29
21 MintState 12252 10-29
20 MintState 11072 10-29
19 MintState 11528 10-29
열람중 MintState 12517 10-29
17 MintState 10570 10-29
16 MintState 9790 10-29
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™