제목 간단한 이메일 보내기 클래스
등록자 미랑 등록일시 2008-03-05 조회수 253 HIT
<?php
/*------------------------------------------------------------------*
* 개 발 자 : 윤석규                                                   
*-------------------------------------------------------------------*
* 이 메 일 : nanummp3@naver.com                                       
*-------------------------------------------------------------------*
* 홈페이지 : http://www.ysksoft.com                                   
*-------------------------------------------------------------------*/

class yskEmailClass {

    var $_from;
    var $_to;
    var $_name;
    var $_title;
    var $_content;
    var $_header;
    var $_bound;
    var $_file = array();

    function init($arr) {
        $this->_from    = $arr['from'];
        $this->_to        = $arr['to'];
        $this->_name    = $arr['name'];
        $this->_title    = $arr['title'];
        $this->_content    = $arr['content'];
        $this->_file    = $arr['file'];
        $this->_bound    = '-------www.ysksoft.com='.md5(microtime());
        return $this->_header();
    }

    function _header() {
        $this->_header    = 'Return-Path: '.$this->_to."\n";
        $this->_header .= 'From: '.$this->_name.' <'.$this->_to.'>'."\n";
        if($this->_file[0]['file']) {
            $this->_header .= 'Content-Type: multipart/mixed; boundary="'.$this->_bound.'"'."\n";
            $this->_fileContentHeader();
        } else {
            $this->_header .= 'Content-Type: text/html; charset=euc-kr'."\n";
        }
        $this->_header .= 'MIME-Version: 1.0'."\n";
        return $this->_send();
    }

    function _fileContentHeader() {
        $x = 1;
        $count = count($this->_file);
        foreach($this->_file as $v) {
            $file_name = basename($v['name']);
            $fp = @fopen($v['file'], 'r');
            $file_content = @fread($fp, filesize($v['file']));
            @fclose($fp);
            $file_content = base64_encode($file_content);

            if($v['type'] == '') {
                $file_type = 'application/octet-stream';
            } else {
                $file_type = $v['type'];
            }

            $file_tmp .= 'Content-Type: '.$file_type.'; name="'.$file_name.'"'."\n";
            $file_tmp .= 'Content-Transfer-Encoding: base64'."\n\n";
            $file_tmp .= $file_content."\n";
            if($x < $count) {
                $file_tmp .= '--'.$this->_bound."\n";
            }
            $x++;
        }

        $tmp  = '--'.$this->_bound."\n";
        $tmp .= 'Content-Type: text/html; charset=euc-kr'."\n";
        $tmp .= 'Content-Transfer-Encoding: 8bit'."\n\n";
        $tmp .= (str_replace('/temp/' ,'/email/', $this->_content))."\n\n";
        $tmp .= '--'.$this->_bound."\n";
        $tmp .= $file_tmp;
        $this->_content = $tmp;
    }

    function _send() {
        $result = mail($this->_from, $this->_title, $this->_content, $this->_header);
        return $result;
    }
}
?>

------------------사용법------------------
<?
## 첨부파일 포함할때
$arr_file = array();
for($x=0; $x<1; $x++) { //$x 는 파일을 몇개 포함할 것인가
  $arr_file[$x]['file'] = '실제존재하는파일경로 절대 경로로하세요';
  $arr_file[$x]['name'] = '파일이름';
  switch($ext) { //$ext 확장자값만 받으세요~
    case 'gif':
        $arr_file[$x]['type'] = 'image/gif';
                              break;
    case 'jpg':
    case 'jpeg':
        $arr_file[$x]['type'] = 'image/jpeg';
                    break;
    case 'png':
        $arr_file[$x]['type'] = 'image/png';
        break;
    case 'bmp':
        $arr_file[$x]['type'] = 'image/bmp';
        break;
    default:
        $arr_file[$x]['type'] = '';
        break;
  }
}

$arr_email            = array();
$arr_email['from']        = '받는사람이메일주소';
$arr_email['to']        = '보내는사람이메일주소';
$arr_email['name']        = '보내는사람이름';
$arr_email['title']        = '제목';
$arr_email['content']                  = '내용';
$arr_email['file'] = $arr_file;

$cls = new yskEmailClass;
$result = $cls->init($arr_email);
if($result == true) {
  echo 1;
} else {
  echo 0;
}
?>
목록보기

        X  
31  PHP7 클래스 선언 방법  2021-11-03 50
30  PHP7 배열 선언 코드  2021-11-03 337
29  PHP 코드를 최적화하는 40가지 팁 (번역)  2009-12-23 297
28  if , else 조건문 코드 줄이기 (?:)  2009-12-23 167
 간단한 이메일 보내기 클래스  2008-03-05 253
26  업로드 이미지 사이즈 처리  2006-05-23 192
25  첨부 이미지(스샷) 사이즈 조정  2006-05-15 135
24  SMS 발송 - 명단 입력 스크립트  2005-09-16 136
23  PHP 로 TTF 파일을 웹폰트로 만들기  2006-05-28 276
22  glob -- Find pathnames matching a pattern  2006-05-18 196
21  Thumbnail Image (GD 처리)  2006-05-15 245
20  PHP Fuction 검색 창 소스  2006-04-11 202
19  이미지 파일의 가로, 세로 픽셀 알아내기  2006-04-11 165
18  테스트용 변수 출력 소스  2006-04-06 168
17  리눅스 apache, php 에서 mssql connecting 하기  2005-06-07 348
16  php를 이용하여 서버 백업 프로그램 짜기  2004-05-04 311
15  베이비 헤로스 이벤트 소스  2004-04-28 143
14  세션 생성..  2004-04-21 200
13  제로보드 view.php 분석  2004-04-07 153
12  다중 게시판 검색  2004-03-25 1173
1 2