send email 작동법?

send email 작동법?

QA

send email 작동법?

본문

안녕하세요. ^^ 

매일매일 qna에 글쓰는것같네요;;ㅠ 으엉

메인 하단에 아래 이미지와 같이 send email 폼을 만들려 하는데요.

 

form/lable/input 사용해서 모양은 갖출 수 있는데

쓴 내용을 가지고 메일을 직접 보내는 액션은 어떻게 취하는 건지.. 모르겠습니다.

 

혹시 스킨같은게 있을라나 하고 찾아봤는데 꼭 맞는 스킨은 없더라고요.

송구스럽지만 힌트 혹은 조언 부탁드리겠습니다.

 

643b171f6f5f62653c42625884f33fdf_1444112184_2974.PNG
 

이 질문에 댓글 쓰기 :

답변 1

<?php
if (!defined('_GNUBOARD_')) exit;

include_once(G5_PHPMAILER_PATH.'/class.phpmailer.php');

// 메일 보내기 (파일 여러개 첨부 가능)
// type : text=0, html=1, text+html=2
function mailer($fname, $fmail, $to, $subject, $content, $type=0, $file="", $cc="", $bcc="")
{
    global $config;
    global $g5;

    // 메일발송 사용을 하지 않는다면
    if (!$config['cf_email_use']) return;

    if ($type != 1)
        $content = nl2br($content);

    $mail = new PHPMailer(); // defaults to using php "mail()"
    if (defined('G5_SMTP') && G5_SMTP) {
        $mail->IsSMTP(); // telling the class to use SMTP
        $mail->Host = G5_SMTP; // SMTP server
    }
    $mail->From = $fmail;
    $mail->FromName = $fname;
    $mail->Subject = $subject;
    $mail->AltBody = ""; // optional, comment out and test
    $mail->MsgHTML($content);
    $mail->AddAddress($to);
    if ($cc)
        $mail->AddCC($cc);
    if ($bcc)
        $mail->AddBCC($bcc);
    //print_r2($file); exit;
    if ($file != "") {
        foreach ($file as $f) {
            $mail->AddAttachment($f['path'], $f['name']);
        }
    }
    return $mail->Send();
}

// 파일을 첨부함
function attach_file($filename, $tmp_name)
{
    // 서버에 업로드 되는 파일은 확장자를 주지 않는다. (보안 취약점)
    $dest_file = G5_DATA_PATH.'/tmp/'.str_replace('/', '_', $tmp_name);
    move_uploaded_file($tmp_name, $dest_file);
    /*
    $fp = fopen($tmp_name, "r");
    $tmpfile = array(
        "name" => $filename,
        "tmp_name" => $tmp_name,
        "data" => fread($fp, filesize($tmp_name)));
    fclose($fp);
    */
    $tmpfile = array("name" => $filename, "path" => $dest_file);
    return $tmpfile;
}

/*
// 메일 보내기 (파일 여러개 첨부 가능)
// type : text=0, html=1, text+html=2
function mailer($fname, $fmail, $to, $subject, $content, $type=0, $file="", $cc="", $bcc="")
{
    global $config;
    global $g5;

    // 메일발송 사용을 하지 않는다면
    if (!$config['cf_email_use']) return;

    $boundary = uniqid(time());

    $header = "Message-ID: <".generate_mail_id(preg_replace("/@.+$/i","",$to)).">\r\n".
              "From:=?utf-8?B?".base64_encode($fname)."?=<$fmail>\r\n";
    if ($cc)  $header .= "Cc: $cc\n";
    if ($bcc) $header .= "Bcc: $bcc\n";
    $header .= "MIME-Version: 1.0\n";
    $header .= "X-Mailer: SIR Mailer 0.94 : {$_SERVER['SERVER_ADDR']} : {$_SERVER['REMOTE_ADDR']} : ".G5_URL." : {$_SERVER['SCRIPT_NAME']} : {$_SERVER['HTTP_REFERER']} \n";
    $header .= "Date: ".date ("D, j M Y H:i:s T",time())."\r\n".
               "To: $to\r\n".
               "Subject: =?utf-8?B?".base64_encode($subject)."?=\r\n";

    if ($file == "") {
        $header .= "Content-Type: MULTIPART/ALTERNATIVE;\n".
                   "              BOUNDARY=\"$boundary\"\n\n";
    } else {
        $header .= "Content-Type: MULTIPART/MIXED;\n".
                   "              BOUNDARY=\"$boundary\"\n\n";
    }

    if ($type == 2)
        $content = nl2br($content);

    $strip_content  = stripslashes(trim($content));
    $encode_content = chunk_split(base64_encode($strip_content));

    $body = "";
    $body .= "\n--$boundary\n";
    $body .= "Content-Type: TEXT/PLAIN; charset=utf-8\n";
    $body .= "Content-Transfer-Encoding: BASE64\n\n";
    $body .= $encode_content;
    $body .= "\n--$boundary\n";

    if ($type) {
        $body .= "Content-Type: TEXT/HTML; charset=utf-8\n";
        $body .= "Content-Transfer-Encoding: BASE64\n\n";
        $body .= $encode_content;
        $body .= "\n--$boundary\n";
    }

    if ($file != "") {
        foreach ($file as $f) {
            $body .= "n--$boundary\n";
            $body .= "Content-Type: APPLICATION/OCTET-STREAM; name=$fname\n";
            $body .= "Content-Transfer-Encoding: BASE64\n";
            $body .= "Content-Disposition: inline; filename=$fname\n";

            $body .= "\n";
            $body .= chunk_split(base64_encode($f['data']));
            $body .= "\n";
        }
        $body .= "--$boundary--\n";
    }

    $mails['to'] = $to;
    $mails['from'] = $fmail;
    $mails['text'] = $header.$body;

    if (defined(G5_SMTP)) {
        ini_set('SMTP', G5_SMTP);
        @mail($to, $subject, $body, $header, "-f $fmail");
    } else {
        new maildaemon($mails);
    }
}

// 파일 첨부시
$fp = fopen(__FILE__, "r");
$file[] = array(
    "name"=>basename(__FILE__),
    "data"=>fread($fp, filesize(__FILE__)));
fclose($fp);

// 메일 유효성 검사
// core PHP Programming 책 참고
// hanmail.net , hotmail.com , kebi.com 등이 정상적이지 않음으로 사용 불가
function verify_email($address, &$error)
{
    global $g5;

    $WAIT_SECOND = 3; // ?초 기다림

    list($user, $domain) = explode("@", $address);

    // 도메인에 메일 교환기가 존재하는지 검사
    if (checkdnsrr($domain, "MX")) {
        // 메일 교환기 레코드들을 얻는다
        if (!getmxrr($domain, $mxhost, $mxweight)) {
            $error = '메일 교환기를 회수할 수 없음';
            return false;
        }
    } else {
        // 메일 교환기가 없으면, 도메인 자체가 편지를 받는 것으로 간주
        $mxhost[] = $domain;
        $mxweight[] = 1;
    }

    // 메일 교환기 호스트의 배열을 만든다.
    for ($i=0; $i<count($mxhost); $i++)
        $weighted_host[($mxweight[$i])] = $mxhost[$i];
    ksort($weighted_host);

    // 각 호스트를 검사
    foreach($weighted_host as $host) {
        // 호스트의 SMTP 포트에 연결
        if (!($fp = @fsockopen($host, 25))) continue;

        // 220 메세지들은 건너뜀
        // 3초가 지나도 응답이 없으면 포기
        socket_set_blocking($fp, false);
        $stoptime = G5_SERVER_TIME + $WAIT_SECOND;
        $gotresponse = false;

        while (true) {
            // 메일서버로부터 한줄 얻음
            $line = fgets($fp, 1024);

            if (substr($line, 0, 3) == '220') {
                // 타이머를 초기화
                $stoptime = G5_SERVER_TIME + $WAIT_SECOND;
                $gotresponse = true;
            } else if ($line == '' && $gotresponse)
                break;
            else if (G5_SERVER_TIME > $stoptime)
                break;
        }

        // 이 호스트는 응답이 없음. 다음 호스트로 넘어간다
        if (!$gotresponse) continue;

        socket_set_blocking($fp, true);

        // SMTP 서버와의 대화를 시작
        fputs($fp, "HELO {$_SERVER['SERVER_NAME']}\r\n");
        echo "HELO {$_SERVER['SERVER_NAME']}\r\n";
        fgets($fp, 1024);

        // From을 설정
        fputs($fp, "MAIL FROM: </@.+$/i","",$to)).">\r\n".
            "From:=?utf-8?B?".base64_encode('보내는사람')."?=<$from>\r\n".
            "MIME-Version: 1.0\r\n";

  if(!$mta) $header .= "Date: ".date ("D, j M Y H:i:s T",time())."\r\n".
                       "To: $to\r\n".
                       "Subject: $title\r\n";

  $header .= "Content-Type: multipart/alternative;\r\n".
             "              boundary=\"$boundary\"\r\n\r\n";

  return $header;
}


function get_boundary_msg() {
  $uniqchr = uniqid("");
  $one = strtoupper($uniqchr[0]);
  $two = strtoupper(substr($uniqchr,0,8));
  $three = strtoupper(substr(strrev($uniqchr),0,8));
  return "----=_NextPart_000_000${one}_${two}.${three}";
}
*/
?> 

답변을 작성하시기 전에 로그인 해주세요.
전체 23
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT