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

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

페이지 정보

작성자 MintState 댓글 0건 조회 12,583회 작성일 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건 3 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
115 MintState 12578 11-10
열람중 MintState 12584 10-29
113 MintState 12597 11-03
112 MintState 12602 10-31
111 MintState 12643 10-31
110 MintState 12647 11-10
109 MintState 12683 11-03
108 MintState 12858 11-03
107 MintState 12878 11-10
106 MintState 12896 10-29
105 MintState 12954 11-03
104 MintState 12960 11-10
103 MintState 13024 11-10
102 MintState 13052 10-31
101 MintState 13090 11-03
100 MintState 13098 10-28
99 MintState 13203 11-03
98 MintState 13263 02-26
97 MintState 13352 10-31
96 MintState 13356 11-10
95 MintState 13384 10-21
94 MintState 13441 11-03
93 MintState 13462 10-28
92 MintState 13480 10-29
91 MintState 13488 02-25
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™