gmail smtp 함수 > 그누보드5 팁자료실

그누보드5 팁자료실

gmail smtp 함수 정보

gmail smtp 함수

본문

지메일 smtp 기능을 활용한 메일 발송 함수입니다. 제 경험으론 그누보드 자체 메일발송을 썼을 때는 스팸메일로 분류되는 경우가 종종 있었는데 지메일을 이용하니 문제가 없어지더군요. 제가 설정을 잘 못해서 그런걸 수도 있는데 아무튼 필요하실 분들이 있을듯 하여.. 

비슷한 팁은 이전에도 본듯 한데 찾아보기가 힘들어서 그냥 올립니다.

그누보드에 이미 올려진 팁을 좀더 간소화했습니다.

 

아래 코드를 extend/user.config.php 에 복사합니다.

 


//gmail SMTP 설정
function Gmailer($to, $subject, $content, $type=1)
{
    global $config;
    global $g5;
    // 메일발송 사용을 하지 않는다면
    if (!$config['cf_email_use']) {
        return;
    }
    if ($type != 1) {
        $content = nl2br($content);
    }
    include_once(G5_PHPMAILER_PATH.'/PHPMailerAutoload.php');
    $mail = new PHPMailer(); // defaults to using php "mail()"
    if (defined('G5_SMTP') && G5_SMTP) {
        $mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "ssl";
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 465;
        $mail->Username = "*** 개인정보보호를 위한 이메일주소 노출방지 ***"; //사용할 지메일 계정
        $mail->Password = "myGooglePW"; //구글계정 패스워드
    }
    $mail->CharSet = 'UTF-8';
    $mail->From = "*** 개인정보보호를 위한 이메일주소 노출방지 ***"; //발송메일(=사용할 지메일 계정)
    $mail->FromName = "메일발송자명";
    $mail->Subject = $subject;
    $mail->AltBody = ""; // optional, comment out and test
    $mail->msgHTML($content);
    $mail->addAddress($to);
    return $mail->send();
}

 

 

그리고 원하는 곳에서

Gmailer("수신메일주소", "메일제목", "메일내용")

를 실행하면 됩니다.

추천
6

댓글 13개

현재 그누보드내에 보면 메일발송을 실행하는 파일들이 있습니다. 예를 들면, 회원가입 후 축하메일 보낸다든지 인증메일 보낸다든지 하는 건데 파일은 bbs/register_form_update.php이죠.

여기서 보면 메일을 보내는 소스가 있는데 아마 mailer(...); 인가 그럴 겁니다. 이 부분을 위 함수로 대체하면 된다는 거죠. 그외 메일 보내는 로직을 직접 짤때도 위 함수를 이용하면 되겠습니다.
고맙습니다.
닷홈 호스팅을 사용하는 바람에 이제서야 보았네요.
닷홈 문제점은 컴퓨터에서 홈페이지 상품을 몇번 클릭하면 블럭을 시켜버리니
불편한점이 많더군요. 휴대폰으로 보는것은 블럭을 시키지 않더군요.
기가 인터넷 시대이니 개인서버로 돌아갈까 합니다. 전기세가 많이 나오더라도 말입니다.
개인서버 문제는 이메일이 문제인데 지구인님의 방법대로 하면 이메일 보내는것이 문제가 없다는 말씀이시지요?
귀한 자료 감사합니다.

참고로 gmail, naver, daum이 아닌 회사 자체 메일을 사용하는 것을 테스트해봤습니다.
lib/mailer.lib.php를 직접 변경하였는데, 가급적이면 지구인님이 올리신것처럼 extend에 새로운 파일을 만들어 사용하시는 것이 좋습니다.

다음의 include_once는 주석처리하셔도 됩니다.
// include_once(G5_PHPMAILER_PATH.'/PHPMailerAutoload.php');

    $mail = new PHPMailer(); // defaults to using php "mail()"
    //$mail->SMTPDebug = 2; // 오류 모니터링을 위해서 개발시에는 설정해서 보시는 것이 개발자의 정신건강에 좋습니다. SMTPDebug 설정시 SMTP와 통신하는 LOG를 보실수 있습니다.
    // $mail->Debugoutput = "html";
    if (defined('G5_SMTP') && G5_SMTP) {
        /* 기존 소스 주석처리
        $mail->IsSMTP(); // telling the class to use SMTP
        $mail->Host = G5_SMTP; // SMTP server
        if(defined('G5_SMTP_PORT') && G5_SMTP_PORT)
            $mail->Port = G5_SMTP_PORT;
        */
        $mail->isSMTP();
        $mail->SMTPAuth = true;
        //$mail->SMTPSecure = "ssl"; // 메일서버가 https가 아니므로 주석처리
        $mail->AuthType = "LOGIN"; // 이 자료가 없어서 고생했는데 이놈이 들어가야 합니다.
        $mail->Host = "mail.company.co.kr"; // 자체 메일서버
        $mail->Port = 25; // SMTP Port
        $mail->Username = "*** 개인정보보호를 위한 이메일주소 노출방지 ***"; // 메일서버에 등록된 계정
        $mail->Password = "비밀번호"; // 메일계정의 비밀번호
    }

참고자료
Debug levels
    Setting the PHPMailer->SMTPDebug property to these numbers or constants (defined in the SMTP class) results in different amounts of output:
    SMTP::DEBUG_OFF (0): Disable debugging (you can also leave this out completely, 0 is the default).
    SMTP::DEBUG_CLIENT (1): Output messages sent by the client.
    SMTP::DEBUG_SERVER (2): as 1, plus responses received from the server (this is the most useful setting).
    SMTP::DEBUG_CONNECTION (3): as 2, plus more information about the initial connection - this level can help diagnose STARTTLS failures.
    SMTP::DEBUG_LOWLEVEL (4): as 3, plus even lower-level information, very verbose, don't use for debugging SMTP, only low-level problems.

Debug output format
    The form that the debug output takes is determined by the Debugoutput property.
    This has several options:
    echo Output plain-text as-is, appropriate for CLI
    html Output escaped, line breaks converted to <br>, appropriate for browser output
    error_log Output to error log as configured in php.ini
전체 2,412 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

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