1. config.php 파일

define('G5_PHPMAILER_PATH', G5_LIB_PATH.'/PHPMailer');

define('G5_SMTP', 'smtp.gmail.com');
define('G5_SMTP_PORT', '587');
define('G5_SMTP_SECURE', 'TLS');
define('G5_SMTP_USER', '2단계 설정한 구글계정');
define('G5_SMTP_PW', '2단계 앱비밀번호 입력');

 

2. lib 폴더 하위에 PHPMailer 설치 

https://github.com/PHPMailer/PHPMailer/releases 접속하여 압축파일 다운

 

3. lib/mailer.lib.php 수정

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

require(/home/admin/plugin/PHPMailer/src/Exception.php): failed to open stream: No such file or directory in /home/admin/lib/mailer.lib.php on line 5, referer: https://kmac360.com/adm/sendmail_test.php


// PHPMailer 클래스 파일 포함
require G5_PHPMAILER_PATH.'/src/Exception.php';
require G5_PHPMAILER_PATH.'/src/PHPMailer.php';
require G5_PHPMAILER_PATH.'/src/SMTP.php';

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

// 메일 보내기 (파일 여러개 첨부 가능)
// 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);
    
    $result = run_replace('mailer', $fname, $fmail, $to, $subject, $content, $type, $file, $cc, $bcc);
    
    if (is_array($result) && isset($result['return'])) {
        return $result['return'];
    }
    
    $mail_send_result = false;
    $mail_error_msg = '';
    
    try {
        // PHPMailer 객체 생성
        $mail = new PHPMailer(true);
        
        // SMTP 설정이 있으면 SMTP로 메일 발송
        if (defined('G5_SMTP') && G5_SMTP) {
            // 디버깅 설정 (서버에서 문제 발생시 활성화)
            $mail->SMTPDebug = 2;  // 0=비활성화, 1=클라이언트, 2=클라이언트/서버
            $mail->Debugoutput = 'html';
            
            // SMTP 사용 설정
            $mail->isSMTP();
            $mail->Host = G5_SMTP;
            
            // SMTP 포트 설정
            if (defined('G5_SMTP_PORT') && G5_SMTP_PORT)
                $mail->Port = G5_SMTP_PORT;
            
            // SMTP 인증 설정
            $mail->SMTPAuth = true;
            
            // SMTP 보안 연결 설정 (ssl 또는 tls)
            if (defined('G5_SMTP_SECURE') && G5_SMTP_SECURE)
                $mail->SMTPSecure = G5_SMTP_SECURE;
            
            // SMTP 계정 정보 설정
            if (defined('G5_SMTP_USER') && defined('G5_SMTP_PW')) {
                $mail->Username = G5_SMTP_USER;
                $mail->Password = G5_SMTP_PW;
            }
            
            // Gmail 특별 설정 (필요한 경우)
            $mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true
                )
            );
        }
        
        // 기본 메일 설정
        $mail->CharSet = 'UTF-8';
        $mail->setFrom($fmail, $fname);
        $mail->addAddress($to);
        $mail->Subject = $subject;
        
        // 메일 내용 설정
        if ($type == 1) {
            $mail->isHTML(true);
            $mail->Body = $content;
            $mail->AltBody = strip_tags($content);
        } else {
            $mail->isHTML(true);  // HTML 형식으로 발송
            $mail->Body = $content;
            $mail->AltBody = strip_tags($content);
        }
        
        // 참조, 숨은참조 추가
        if ($cc)
            $mail->addCC($cc);
        if ($bcc)
            $mail->addBCC($bcc);
        
        // 첨부 파일 추가
        if ($file != "") {
            foreach ($file as $f) {
                $mail->addAttachment($f['path'], $f['name']);
            }
        }
        
        // 추가 옵션 적용
        $mail = run_replace('mail_options', $mail, $fname, $fmail, $to, $subject, $content, $type, $file, $cc, $bcc);
        
        // 메일 발송
        $mail_send_result = $mail->send();
        
        // 오류 확인
        if (!$mail_send_result) {
            $mail_error_msg = $mail->ErrorInfo;
            error_log("Mailer Error: " . $mail_error_msg);
        }
        
    } catch (Exception $e) {
        $mail_error_msg = $e->getMessage();
        error_log("Mailer Exception: " . $mail_error_msg);
    }
    
    // 이벤트 실행
    run_event('mail_send_result', $mail_send_result, $mail, $to, $cc, $bcc);
    
    // 관리자인 경우 오류 메시지 표시
    if (!$mail_send_result && G5_IS_ADMIN) {
        echo '<div style="color:red;margin-bottom:15px;">메일 발송 실패: ' . $mail_error_msg . '</div>';
    }
    
    return $mail_send_result;
}

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

 

끝.

홈페이지 제작을 할 때, 그누보드로 하는 경우가 많은데 기본 프로그램의 경로를 변경하여 1차적으로 숨기고 싶을 때가 있어서

찾아보니 생각보다 간단하다.

 

기본 그누보드 루트 경로에 있는 config.php 파일내에 변수를 수정하고 경로 폴더를 수정해주면 끝이다.

 

config.php 파일 내 94번째 정도 줄

...
...

define('G5_ADMIN_DIR',      'adm');
define('G5_BBS_DIR',        'bbs');
define('G5_CSS_DIR',        'css');
define('G5_DATA_DIR',       'data');
define('G5_EXTEND_DIR',     'extend');
define('G5_IMG_DIR',        'img');
define('G5_JS_DIR',         'js');
define('G5_LIB_DIR',        'lib');
define('G5_PLUGIN_DIR',     'plugin');
define('G5_SKIN_DIR',       'skin');
define('G5_EDITOR_DIR',     'editor');
define('G5_MOBILE_DIR',     'mobile');
define('G5_OKNAME_DIR',     'okname');

define('G5_KCPCERT_DIR',    'kcpcert');
define('G5_INICERT_DIR',     'inicert');
define('G5_LGXPAY_DIR',     'lgxpay');

define('G5_SNS_DIR',        'sns');
define('G5_SYNDI_DIR',      'syndi');
define('G5_PHPMAILER_DIR',  'PHPMailer');
define('G5_SESSION_DIR',    'session');
define('G5_THEME_DIR',      'theme');

define('G5_GROUP_DIR',      'group');
define('G5_CONTENT_DIR',    'content');


...
...

 

여기서 adm, bbs, theme 를 변경하고자 한다면

define('G5_ADMIN_DIR',      'admin');
define('G5_BBS_DIR',        'board');
define('G5_THEME_DIR',      'thm');

이런식으로 변경을 해주고, 실제 폴더 이름도 변경해주면 된다. 

1. 게시판 스킨 폴더 내에 write.skin.php 안에 하단부에 frwite_submit 함수

 function fwrite_submit(f){

...
...
...
        if (document.getElementById("char_count")) {
            if (char_min > 0 || char_max > 0) {
                var cnt = parseInt(check_byte("wr_content", "char_count"));
                if (char_min > 0 && char_min > cnt) {
                    alert("내용은 "+char_min+"글자 이상 쓰셔야 합니다.");
                    return false;
                }
                else if (char_max > 0 && char_max < cnt) {
                    alert("내용은 "+char_max+"글자 이하로 쓰셔야 합니다.");
                    return false;
                }
            }
        }
        
 ...
 ...
 여기에 코드삽입
 ...
 ...
 
        
       
<?php echo $captcha_js; // 캡챠 사용시 자바스크립트에서 입력된 캡챠를 검사함  ?>
 		// 파일을 첨부 했는지 확인
        var file_check = false;
        $(".frm_file").each(function(){
            if($(this).val()!=""){
                file_check = true;
                return false;
            }
        });
        // 파일을 첨부하지 않았다면 알림과 submit 취소
        if(!file_check){
            alert("파일을 하나 이상 첨부하세요.");
            return false;
        }

 

누보드 DB sql문을 입력하니 아래같은 에러가 발생함.

 

wr_datetime의 유효하지 못한 디폴트 값을 사용하셨습니다.

 

아래 코드를 phpmyAdmin 에서 쿼리문을 돌려준다.

ALTER TABLE `[에러나는_DB_칼럼]` CHANGE `wr_datetime` `wr_datetime` DATETIME NOT NULL;

alter table [에러나는_DB_칼럼] change wr_datetime wr_datetime datetime not null;

 

저는 g5_write_notice 쪽에서 에러가 발생해서 다음과같이 수정했습니다.

 

<style>
/* jquery datepicker 용 간단 CSS */
/* 출처 : https://sir.kr/g5_tip/16589 */

#ui-datepicker-div { background: #fff; margin: 5px 0 0 0; padding-top: 25px; box-shadow: 10px 10px 40px rgb(0 0 0 / 10%); }
#ui-datepicker-div .ui-datepicker-header { position: relative; margin-left: 20px; margin-right: 20px; }
#ui-datepicker-div .ui-datepicker-prev { position: absolute; display: inline-block; font-size: 12px; top: -23px; left: 0; }
#ui-datepicker-div .ui-datepicker-next { position: absolute; display: inline-block; font-size: 12px; top: -23px; right: 0; }
#ui-datepicker-div .ui-datepicker-title { position: relative; clear: both; margin-top: 10px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
#ui-datepicker-div .ui-datepicker-title select { height: auto; width: calc( 50% - 15px); min-width: 90px; padding: 4px 12px; border-radius: 0; }
#ui-datepicker-div .ui-datepicker-calendar { margin-left: 20px; margin-right: 20px; }
#ui-datepicker-div .ui-datepicker-calendar th,
#ui-datepicker-div .ui-datepicker-calendar td { width: 35px; height: 30px; text-align: center; line-height: 30px; }
#ui-datepicker-div .ui-datepicker-calendar th:first-child > span,
#ui-datepicker-div .ui-datepicker-calendar td:first-child > a { color: #dc3545; }
#ui-datepicker-div .ui-datepicker-calendar th:last-child > span,
#ui-datepicker-div .ui-datepicker-calendar td:last-child > a { color: #007bff; }
#ui-datepicker-div .ui-datepicker-calendar .ui-state-active { padding: 3px 6px; background: #6f42c1; color: #fff; font-weight: 600; }
#ui-datepicker-div .ui-datepicker-buttonpane { margin-top: 10px; display: flex; }
#ui-datepicker-div .ui-datepicker-buttonpane > button { flex: 1 1 50%; max-width: 50%; text-align: center; padding: .375rem; }
#ui-datepicker-div .ui-datepicker-buttonpane > button:first-child { order: 2; background: #dc3545; color: #fff; }
#ui-datepicker-div .ui-datepicker-buttonpane > button:last-child  { order: 1; }
 
</style>

그누보드는 기본적으로 Datepicker 플러그인을 포함하고 있다(최신버전기준)

 

 

게시판 스킨 작성 파일에(write파일) 

<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

include_once(G5_PLUGIN_PATH.'/jquery-ui/datepicker.php'); // 플러그인 인클루드

...

...

...

<input class="datepicker frm_input" >

상단에 인클루드 해주고, 클래스 datepicker 추가해준다.

 

그리고 최하단에 스크립트 삽입하기

<!-- 달력 시작-->
<script type="text/javascript">
//<![CDATA[
$(function(){
    $(".datepicker").datepicker({
        dateFormat: "yy-mm-dd",
        onSelect:function(dateText, inst) {
            console.log(dateText);
            console.log(inst);
        }
    });
    $(".targetFocus").click(function(){
        $($(this).data("target")).focus();
    });
});
//]]>
</script><!-- 달력 끝 -->

 

날짜 포맷 방식 : dateFormat: "yy-mm-dd"

yy-mm-dd : 2015-10-25

yy/mm/dd : 2015/10/25

yy.mm.dd : 2015.10.25

yymmdd : 20151025

 

 

유튜브 영상 게시판 및 최신글 스킨 제작 시에 

영상 링크 입력 및 해당 영상의 썸네일을 노출시켜야 할때 필요한 정보이다.

 

영상은 ID 값만 입력시키도록 하였고 

해당 ID로 영상 재생 및 썸네일까지 긁어올 수 있다. 

 

ID만 으로 썸네일 긁어올 수 있고, 해상도도 정해서 가져올 수 있다.

 

 

http://img.youtube.com/vi/동영상ID/이미지형식.jpg

http://i.ytimg.com/vi/동영상ID/이미지형식.jpg

이미지형식이 해상도를 정할 수 있다.

- 고품질 (480 x 360) : hqdefault.jpg

- 중간품질 (320 x 180) : mqdefault.jpg

- 보통품질 (120 x 90) : default.jpg

동영상 배경이미지 (480 x 360) : 0.jpg

 

 

메인화면에서, 최신글 스킨으로 첨부파일을 출력하도록 했으나 '잘못된 접근' 이라는 오류가 발생..

 

세션체크와 같이 들어가는 부분이라, 세션체크도 해줘야함.

 

메인에서 불러오는 최신글 스킨 for문 안에 코드 추가했더니 해결.

 

$ss_name = "ss_view_{$bo_table}_{$list[ $i]['wr_id']}";

if (!get_session($ss_name)); set_session($ss_name, TRUE);

 

<?php

/* root/about.php */
include_once('./common.php');

/* root/theme/basic/dir/about.php */
include_once('../../../common.php');


/* root/sub/about.php 의 경우 ../common.php로 */

$g5['title'] = "새로운 페이지";
include_once(G5_PATH.'/head.php');

?>

<!-- 새로운 페이지 내용 작성 부분 -->

<!-- 새로운 페이지 내용 작성 부분 -->


<?php

include_once(G5_PATH.'/tail.php');

?>

 

ini_set('display_errors', 1);

ini_set('error_reporting', E_ALL);

 

페이지 상단에 삽입

config.php 파일

 

+ Recent posts