카테고리 또는 옵션에 따라 알림 메일 주소 변경

글 작성시 카테고리를 "수급요청"으로 설정하면

게시판에 설정된 알림 메일 주소 외에 추가로 지정된 사람에게 보내는 기능 가능할까요?

 

아니면 옵션(체크박스)의 값에 따라 메일을 보내기 가능할지..

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  • 안녕하세요~^^

    KBoard 플러그인 kboard_document_insert 액션을 사용하시면

    게시글 등록 후 새로운 코드를 실행하게 할 수 있습니다.

     

    카테고리에 따라 다른 이메일 알림을 보내시려면

    워드프레스 관리자 -> 외모 -> 테마 편집기 페이지에서 functions.php 파일 하단에

    아래의 코드를 활용해보시겠어요?

    add_action('kboard_document_insert', 'my_kboard_document_insert', 10, 4);
    function my_kboard_document_insert($content_uid, $board_id, $content, $board){
    	if($content->category1 == '수급요청' && $board_id == '1'){ // 실제 게시판 id로 적용해주세요.
    		$user_email = '이메일주소';
    		
    		$url = new KBUrl();
    		$mail = kboard_mail();
    		$mail->to = $user_email;
    		$mail->title = apply_filters('kboard_latest_alerts_subject', '['.__('KBoard new document', 'kboard').'] '.$board->board_name.' - '.$content->title, $content);
    		$mail->content = apply_filters('kboard_latest_alerts_message', $content->getDocumentOptionsHTML() . $content->content, $content);
    		$mail->url = $url->getDocumentRedirect($content->uid);
    		$mail->url_name = __('Go to Homepage', 'kboard');
    		$mail->send();
    	}
    }

    위의 코드에서 수급요청 부분은 카테고리1 입니다.

    $board_id == '1' 부분은 실제 게시판 id로 적용해서 확인해보시겠어요?

    고맙습니다.

  • "No body specified"

    위와 같이 했더니 메일로그에 이런 메세지와 함께 전송이 안됩니다. 

    어떤 문제일까요

  • 안녕하세요.

    이메일주소 부분에는 실제 이메일 주소로 적용해주셨는지요?

    저희 쪽에서 해당 코드로 테스트해보니 정상적으로 동작하는 것을 확인했습니다.

     

    스팸 메일함에도 메일이 없는지요?

    메일 전송에 문제가 있다면,

    WP Mail SMTP 플러그인을 사용해서 외부 메일에서 보내지도록 세팅해보시겠어요?

    https://ko.wordpress.org/plugins/wp-mail-smtp/

     

    위의 플러그인으로도 해결이 되지 않는다면

    이메일을 전송하는 기능은 서버 쪽의 영향을 받기 때문에

    서버 관리자나 호스팅 업체에 문의를 해보셔야 할 듯합니다.

     

    아래 관련 링크도 참고해보시겠어요?

    워드프레스 이메일 전송 문제 해결 방법

    고맙습니다.

  • 전송 실패한 로그 보면 아래 정보만 나옵니다.

    성공한. 카테고리 구분하지 않고 그냥 게시판에 적었을때는 게시판에 적응 내용까지 나옵니다.

    session transcript를 보면 이런 경고 문구(?) 있습니다.

     

    그리고 Post SMTP 옵션에서 이 메일을 Resend 해서 다시 보내면 코드가 깨진채로 옵니다.

     

     

     

  • 안녕하세요.

    카테고리를 구분하지 않고 보낸 메일은 어떻게 보내신 건지요?

    KBoard 플러그인 기본 기능인 최신글 이메일 알림 기능으로 보내신 건지요?

    테마 쪽 functions.php 파일은 워드프레스 관리자 페이지에서 수정하신 건지요?

     

    만약, FTP로 직접 접속해서 수정하셨다면 UTF-8 인코딩으로 저장해주셔야 합니다.

    Notepad++라는 무료 편집기를 사용해보세요.

    에디터에서 특별한 설정은 필요하지 않습니다.

    한글도 지원하기 때문에 추천드립니다.

    https://notepad-plus-plus.org/

     

    그래도 해결되지 않으신다면,

    저희 고객지원 쪽 이메일로 워드프레스 관리자 계정과 FTP 접속 정보를 보내주시면 점검해드리겠습니다.

    KBoard 플러그인 쪽의 문제가 아니라면 해결을 보장해드리긴 어렵습니다.

    고맙습니다.

  • <?php
    // Exit if accessed directly
    if ( !defined( 'ABSPATH' ) ) exit;
    
    // BEGIN ENQUEUE PARENT ACTION
    // AUTO GENERATED - Do not modify or remove comment markers above or below:
    
    if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
        function chld_thm_cfg_locale_css( $uri ){
            if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
                $uri = get_template_directory_uri() . '/rtl.css';
            return $uri;
        }
    endif;
    add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );
             
    if ( !function_exists( 'child_theme_configurator_css' ) ):
        function child_theme_configurator_css() {
            wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'font-awesome','simple-line-icons','magnific-popup','slick','oceanwp-style' ) );
        }
    endif;
    add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 10 );
    
    // END ENQUEUE PARENT ACTION
    
    add_filter('kboard_latest_alerts_attachments', 'my_latest_alerts_attachments', 10, 2);
    function my_latest_alerts_attachments($attachments, $content){
    	return array();
    }
    
    
    add_filter('kboard_latest_alerts_subject', 'my_kboard_latest_alerts_subject', 10, 2);
    function my_kboard_latest_alerts_subject($subject, $content){
    	$board = $content->getBoard();
    	if($board->id=='26'){
    		$subject = '['.$board->board_name.']' . $content->title . $content->option->{'slect_key'};
    	} else {
    		$subject = '['.$board->board_name.']' . $content->title;
    	}
    	return $subject;
    }
    
    add_action('kboard_comments_insert', 'my_kboard_comments_insert', 10, 2);
    function my_kboard_comments_insert($insert_id, $content_uid){
        $comment = new KBComment();
        $comment->initWithUID($insert_id);
        $document = new KBContent();
        $document->initWithUID($content_uid);
    
        if($document->member_uid){
            $user = new WP_User($document->member_uid);
    
            if($user->user_email){
                if(!class_exists('KBMail')){
                    include_once KBOARD_DIR_PATH . '/class/KBMail.class.php';
                }
                    
                $url = new KBUrl();
                $mail = new KBMail();
                $mail->to = $user->user_email;
                $mail->title = "[댓글알림] {$document->title}";
                $mail->content = $comment->content;
                $mail->url = $url->getDocumentRedirect($document->uid);
                $mail->send();
            }
        }
    }
    
    
    add_action('kboard_document_insert', 'my_kboard_document_insert', 10, 4);
    function my_kboard_document_insert($content_uid, $board_id, $content, $board){
    	if($content->category1 == 'porting' && $board_id == '26'){ // 실제 게시판 id로 적용해주세요.
    		$user_email = 'gagdoc2@gmail.com';
    		
    		$url = new KBUrl();
    		$mail = kboard_mail();
    		$mail->to = $user_email;
    		$mail->title = apply_filters('kboard_latest_alerts_subject', '['.__('KBoard new document', 'kboard').'] '.$board->board_name.' - '.$content->title, $content);
    		$mail->content = apply_filters('kboard_latest_alerts_message', $content->getDocumentOptionsHTML() . $content->content, $content);
    		$mail->url = $url->getDocumentRedirect($content->uid);
    		$mail->url_name = __('Go to Homepage', 'kboard');
    		$mail->send();
    	}
    }

    ftp 접속은 아니고 네트워크 드라이브로 접속해서 수정했습니다.

    notepad로 수정을했고 utf8 문서 입니다.

     

    차일드 테마의 function.php 입니다.

  • 코드 상에는 문제없는 듯합니다.

    올려주신 코드 중 kboard_document_insert 액션에서

    카테고리에 따라 메일을 보내는 코드를 테스트해보니

    저희 쪽 테스트 서버에서는 정상적으로 동작하는 것을 확인했습니다.

     

    이전 댓글에 안내해드린 것처럼

    이메일을 전송하는 기능은 서버 쪽의 영향을 받기 때문에

    혹시, 서버 쪽에서 제한하고 있는 건 아닌지 확인해보셔야 할 듯합니다.

    서버 관리자나 호스팅 업체에도 문의를 해보시는 게 좋을 듯합니다.

    고맙습니다.

좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기