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

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

페이지 정보

작성자 MintState 댓글 0건 조회 12,531회 작성일 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건 5 페이지
PHP 목록
번호 제목 글쓴이 조회 날짜
65 MintState 13039 11-03
64 MintState 13001 10-31
63 MintState 12978 11-10
62 MintState 12911 11-10
61 MintState 12907 11-03
60 MintState 12848 10-29
59 MintState 12835 11-10
58 MintState 12809 11-03
57 MintState 12633 11-03
56 MintState 12601 10-31
55 MintState 12600 11-10
54 MintState 12556 10-31
53 MintState 12548 11-03
열람중 MintState 12532 10-29
51 MintState 12530 11-10
50 MintState 12526 11-03
49 MintState 12485 10-28
48 MintState 12476 11-10
47 MintState 12455 11-03
46 MintState 12428 02-23
45 MintState 12321 11-03
44 MintState 12291 10-29
43 MintState 12288 11-17
42 MintState 12280 11-03
41 MintState 12271 10-31
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2024, YesYo.com MintState. ™