G4S / (수정) 네이버 smtp를 이용하여, 메일 보내는 예제 (g4s-4.0b41 기준) > 그누보드5 팁자료실

그누보드5 팁자료실

G4S / (수정) 네이버 smtp를 이용하여, 메일 보내는 예제 (g4s-4.0b41 기준) 정보

G4S / (수정) 네이버 smtp를 이용하여, 메일 보내는 예제 (g4s-4.0b41 기준)

본문

먼저, 그누보드를 개발 및 공개해 주시는 에스아이알소프트에 진심으로 감사의 말씀을 전합니다.

그누보드 G4S(현 G5베타)에서 메일 보내기가 잘 안되시는 분들이 참고하시면 도움이 될 듯 합니다. 기존 mailer 함수(PHPMailer 직전에 사용되었던 소스)에서는 GMail 에서 본문이 잘리는 문제가 있었습니다. 

* plugin/PHPMailer_v2.0.4 는 사용하지 않음. 폴더 전체를 삭제함.
* 최신판인 PHPMailer 5.2.7 로 대체함. (http://phpmailer.worxware.com/index.php)
* 필요한 파일: 세개의 파일만 있으면 됨. (class.phpmailer.php, class.smtp.php, PHPMailerAutoload.php)
* 위의 세 파일을 adm/ 폴더 안에 배치하고, 기존 plugin/PHPMailer_v2.0.4 폴더는 삭제함.
* 세 파일 각각 상단에,
if (!defined('_GNUBOARD_')) exit; 
코드를 추가.
* 네이버 메일(네이버 Works)을 smtp 로 이용하여, 이메일 발송용으로 사용.
* 자체 서버에는 메일 수발신용 소프트웨어(예: sendmail)를 설치하지 않고, 오로지 smtp 발송용 소프트웨어만 설치한 상태임. 물론 sendmail 로 링크된 상태임.
* 참고한 소스 : http://phpmailer.worxware.com/index.php?pg=exampleagmail

* 변경한 파일: lib/mailer.lib.php


<<< mailer.lib.php >>>


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

include_once(G4_ADMIN_PATH.'/class.phpmailer.php'); // adm 폴더 안으로 class.phpmailer.php 를 배치한 예제임.
include_once(G4_ADMIN_PATH.'/class.smtp.php'); // adm 폴더 안으로 class.smtp.php 를 배치한 예제임.

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

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

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


///// 아래는 네이버 Works 를 사용했을 때의 설정 예제임. http://mail.naver.com/external/naverworks

    try
    {

        $mail->Host = "For_Abuser"; // 예외를 고려하여, Host 명을 임의의 값으로 설정함.

        $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
        if (defined('G4_SMTP')) {
            $mail->IsSMTP(); // telling the class to use SMTP
            $mail->Host = G4_SMTP; // SMTP server. 루트 디렉토리의 config.php 에서, define('G4_SMTP', 'dsmtp.naver.com') 로 설정되어 있는 값을 끌어옴.
            $mail->Port = 587; // 네이버 SMTP 포트
        }
        //$mail->SMTPDebug  = 2; // enables SMTP debug information, 오류 메시지를 보기 위해서는 주석을 해제하고 2 로 설정할 것. 오류 메시지는 "회원메일발송 > 테스트" 버튼을 실행했을 때에만 나타남.
        $mail->SMTPAuth  = true; // enable SMTP authentication
        $mail->SMTPSecure = "tls";                // sets the prefix to the servier
        $mail->Username = $fmail;
        $mail->Password = "비밀번호";
        $mail->CharSet = "UTF-8"; // class.phpmailer.php 의 기본값이 iso-8859-1 이므로, UTF-8 로 변경함.
        $mail->Encoding = "base64"; // 기본값이 8bit 이므로, base64로 변경함.
        $mail->SetFrom("$fmail", '운영자');
        $mail->AddReplyTo("$fmail", '운영자');
        $mail->AddAddress($to); // 수신자
        $mail->Subject = $subject; // 제목
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
        $mail->MsgHTML($content);

        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']);
            }
        }

        if($mail->Send())
        {
          $message = "메일을 발송했습니다.<p></p>\n";
          return true;
        }
    }

    catch(phpmailerException $e)
    {
      $error = $e->errorMessage(); //Pretty error messages from PHPMailer
      return false;
    }
    catch (Exception $e)
    {
      $error = $e->getMessage(); //Boring error messages from anything else!
      return false;
    }

    return false;
}
?>
추천
2

댓글 8개

메인 폴더에 있는, config.php 에서, define('G4_SMTP', 'dsmtp.naver.com')  여기에 적습니다. naver works 인 경우는 dsmtp.naver.com 이고요, 일반 네이버 계정인 경우는 smtp 주소가 다를 수 있으니, 네이버 계정 내에 설명되어 있는 주소를 적으시면 됩니다. 포트 번호는 위에서도 나와 있듯이,  mailer.lib.php 내에 표기했습니다. (587)
오로지 smtp 발송용 소프트웨어만 설치한 상태임. 물론 sendmail 로 링크된 상태임.
-> 이 말씀의 의미를 좀 설명부탁드릴께요. 워낙 잘 몰라서....  (설명해주신대로 따라한다고 해봤는데... 안되더라구요)

G5beta 5.0b20 버전으로 업데이트 된 상태이구요.
지금 최신 버전에서는 mailer.lib.php 의 내용이 위에 붙여주신 코드와는 좀 많이 다른데요...

G5beta 5.0b20 버전에서도 가능할지... 그리고 가능하다면 어떻게 해야할지.. 좀 부탁드려도 될까요?

저는 sendmail이 설치되어 있는 상태입니다.
위 링크중 * 최신판인 PHPMailer 5.2.7 로 대체함. (http://phpmailer.worxware.com/index.php)  이게 죽었내요 그래서 삭제하라고해서 했지만 링크가 죽어서 결국 받지 못한 상태 입니다 ㅠㅠ 링크 확인좀 해주세요 매일이 안갑니다
저도 이메일 안보내져서 골머리앓다가 겨우 해결했네요 ^^;; phpMailer 5.2.7 버전 다운로드 주소입니다~
http://webscripts.softpedia.com/scriptDownload/PHPMailer-Codeworx-Technologies-Download-46188.html
감사 합니다 이글 덕분에  그노보드  g5에서 이메일 테스트 / 회원 id/pw 칮기 메일 발송이 가능했습니다
============== 아래 제홈피 자료 참조 드립니다 ============
시놀로지 이메일의 모든것_G5에서 회원 PW 잊었을시 변경 메일 보내기 수정하기 ....
http://shimss.ipdisk.co.kr/pc/bbs/board.php?bo_table=s11&wr_id=1001
도움 요청 합니다
요즘 아래와같은 메일이 대량으로전송되고 있어 구글에서 일일메일 발송제한되고 있습니다
해결방법을 아시는분은 리플요청 합니다
=================발송자가 상이하게다량메일발송 합니다  ==========
Delivery to the following recipient failed permanently:

    http://ghalamrang.com/plugin.php?j=114&nMo3Xdv7u9uyn3HH=Dka&9Az=7w7&4G9G=Ti ] These pics will be a good start
전체 2,411 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

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