[G5] 외부 메일로 네이버 메일 사용하기 > 기술자료 | 해피정닷컴

[G5] 외부 메일로 네이버 메일 사용하기 > 기술자료

본문 바로가기

사이트 내 전체검색

[G5] 외부 메일로 네이버 메일 사용하기 > 기술자료

그누보드 [G5] 외부 메일로 네이버 메일 사용하기

페이지 정보


본문

네이버 이메일을 그누보드 SMTP 외부메일 설정에서 사용하는 방법입니다.
환경설정 > 관리자메일 주소는 config.php 에 등록하는 네이버 메일주소와 일치해야 합니다.


네이버 2단계 인증관리 > 애플리케이션 등록
https://help.naver.com/service/5640/contents/8584?lang=ko

 
1. /config.php 173 번째 줄에 있는
define('G5_SMTP',      '127.0.0.1');
define('G5_SMTP_PORT', '25');
 
를 아래와 같이 수정합니다.
 
define('G5_SMTP', 'smtp.naver.com');
define('G5_SMTP_PORT', '587');
define('G5_SMTP_SECURE', 'TLS');
define('G5_SMTP_USER', 'yourid@naver.com');
define('G5_SMTP_PW', 'yourpassword');  // 네이버 앱 비밀번호 (2단계 인증 앱비밀번호)
 

2. /lib/mailer.lib.php 19번째 줄
 
    $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
        if(defined('G5_SMTP_PORT') && G5_SMTP_PORT)
            $mail->Port = G5_SMTP_PORT;
    }
 
를 아래와 같이 수정합니다.
 
    $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
        //if(defined('G5_SMTP_PORT') && G5_SMTP_PORT)
        //    $mail->Port = G5_SMTP_PORT;
        if(defined('G5_SMTP_PORT') && G5_SMTP_PORT) {
            $mail->Port = G5_SMTP_PORT;
        }
        $mail->SMTPAuth = true;
        $mail->AuthType = "LOGIN";
        $mail->SMTPSecure = G5_SMTP_SECURE;
        $mail->Username = G5_SMTP_USER;
        $mail->Password = G5_SMTP_PW;
    }


3. 일반 페이지에서 사용하기
일반페이지에서 사용할때는 별도로 만든 mailer 를 사용하는것이 좋습니다.

3-1. lib / mailer_naver.lib.php  파일 생성

<?php
if (!defined('_GNUBOARD_')) exit;
include_once("_common.php");

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

function mailer_naver($to_email, $to_name, $from_email, $from_name, $subject, $content, $is_html = true) {
    require_once G5_PLUGIN_PATH . '/PHPMailer-6.9.3/src/PHPMailer.php';
    require_once G5_PLUGIN_PATH . '/PHPMailer-6.9.3/src/SMTP.php';
    require_once G5_PLUGIN_PATH . '/PHPMailer-6.9.3/src/Exception.php';

    $mail = new PHPMailer(true);

    try {
        // SMTP 설정
        $mail->isSMTP();
        $mail->Host = 'smtp.naver.com';
        $mail->SMTPAuth = true;
        //$mail->Username = 'yourid@naver.com';  // 네이버 이메일 주소
        //$mail->Password = 'yourpassword';  // 네이버 앱 비밀번호 (2단계 인증 앱비밀번호)
        $mail->Username = G5_SMTP_USER;  // 네이버 이메일 주소
        $mail->Password = G5_SMTP_PW;  // 네이버 앱 비밀번호 (2단계 인증 앱비밀번호) // 의료입자방사선연구회
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // SSL
        $mail->Port = '465'; // 네이버 SMTP 포트

        // 한글 깨짐 방지
        $mail->CharSet = 'UTF-8';
        $mail->Encoding = 'base64';

        // 보내는 사람 설정
        $mail->setFrom($from_email, '=?UTF-8?B?'.base64_encode($from_name).'?=');
        $mail->addAddress($to_email, '=?UTF-8?B?'.base64_encode($to_name).'?=');

        // 메일 제목 한글 깨짐 방지
        $mail->Subject = '=?UTF-8?B?'.base64_encode($subject).'?=';

        // HTML 메일 여부 설정
        $mail->isHTML($is_html);
        $mail->Body = $content;

        // 메일 전송
        return $mail->send();
    } catch (Exception $e) {
        error_log('메일 발송 실패: ' . $mail->ErrorInfo);
        return false;
    }
}


3-2. test_mail.php  파일 생성
웹브라우저로 아래 파일 실행하면 메일이 발송됩니다.

<?php
include_once('./common.php');
//include_once(G5_LIB_PATH.'/mailer.lib.php');
include_once(G5_LIB_PATH.'/mailer_naver.lib.php');

// lib 폴더에 PHPMailer 업로드
// PHPMailer 다운로드 : https://github.com/PHPMailer/PHPMailer

$from_email = $config['cf_admin_email']; // 환경설정에 등록된 이메일주소
$from_name  = $config['cf_admin_email_name']; // 환경설정에 등록된 이름
$to_email   = '받는_이메일주소';  // 받을 이메일 주소
$to_name    = '받는_이름'; // 받는 이름
$mail_subject = 'Title 네이버 SMTP 테스트 메일'; // 이메일 제목
$mail_content = '<p>Message 이메일이 정상적으로 발송되었습니다.</p>'; // 이메일 내용

if (mailer_naver($to_email, $to_name, $from_email, $from_name, $subject, $content)) {
    echo '이메일이 정상적으로 발송되었습니다.';
} else {
    echo '이메일 발송에 실패했습니다.';
}

 
 관련자료
https://sir.kr/g5_tip/22471

댓글목록

등록된 댓글이 없습니다.


Total 2,643건 1 페이지
  • RSS
기술자료 목록
2643
PHP   25  2025-02-07 09:27 ~ 2025-02-07 11:55  
열람
그누보드   22  2025-02-07 08:55 ~ 2025-02-07 15:52  
2641
그누보드   390  2024-11-26 21:14 ~ 2024-11-26 21:22  
2640
그누보드   471  2024-11-22 10:52 ~ 2024-11-22 11:03  
2639
호스팅   408  2024-11-19 14:41 ~ 2024-11-19 21:17  
2638
Linux   329  2024-11-18 15:45 ~ 2024-11-18 15:48  
2637
일반   314  2024-11-15 16:45 ~ 2024-11-15 16:46  
2636
Secure   354  2024-11-06 18:48 ~ 2024-11-06 18:50  
2635
영카트   513  2024-10-21 13:44 ~ 2024-10-21 19:42  
2634
전자결제   1121  2024-09-05 09:30  
2633
MySQL   1180  2024-03-29 14:14 ~ 2024-03-29 14:14  
2632
그누보드   1409  2024-02-23 18:40 ~ 2024-02-24 06:13  
2631
JavaScript   1527  2024-02-16 18:50 ~ 2024-02-16 20:37  
2630
Java   1487  2024-02-06 16:49  
2629
PHP   1691  2024-02-06 16:42  
2628
호스팅   1607  2024-01-29 12:54  
2627
PHP   1520  2024-01-26 11:04 ~ 2024-01-26 11:13  
2626
MySQL   1641  2024-01-08 17:37 ~ 2024-03-14 16:00  
2625
SQL   1885  2024-01-08 12:36  
2624
영카트   1907  2024-01-04 14:57  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2025 해피정닷컴. All Rights Reserved.