정기결제 주문이 들어오면 이메일 알림

안녕하세요. 항상 수고가 많으십니다.

정기결제 주문이 들어오면 이메일 알림 관련해서 아래 링크에 있는 글을 통해서 도움을 받았는데요.

https://www.cosmosfarm.com/threads/document/27230

알려주시 대로 functions.php 파일 하단에 코드를 추가해서 해결했었습니다.

 

그런데 이번에 서버를 AWS Lightsail로 옮기게 되었는데, 거기서는 이메일이 워드프레스 자체 이메일이 사용에 제약이 있어서,

Google Suite를 통해 이메일을 쓰면서, 워드프레스 사이트에는 WP Mail SMTP 라는 플러그인을 사용해서 세팅을 해놓았습니다.

 

그런데 나머지 이메일들은 (Contact form 포함) 다 잘 되는데, 위에 알려주신 코드로 발송되는 이메일이 더 이상 발송되지 않습니다.

혹시 이런 경우는 어떻게 해야 할지 조언해주실 수 있으신지요?

 

아니면 AWS Lightsail을 서버로 쓰시고 계신 다른 분들의 경우는 이메일을 어떻게 쓰고 계신지 알고 계신게 있으신가요?

 

추가로 이번 서버 이전에도, 고객들이 주문하였을 때 고객 이메일로 나이스페이먼츠에서 가는 카드 영수증이 담긴 이메일도 보내지지 않고 있었습니다.

혹시 이 부분에 대해서도 조언해주실 수 있으신지요.

항상 도움 감사하게 받고 있습니다. 감사합니다.

 

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
  • 참고로 아래 링크에서 알려준대로 mailtest.php 해보았더니 The message was not sent!라고 나오면서 역시 전송되지 않았습니다.

    => 다시 해보았더니 The test message was sent. Check your email inbox. 라고 나오면서 이메일이 왔습니다.

    https://www.butlerblog.com/2012/09/23/testing-the-wp_mail-function/

    하지만 여전히 주문 성공시 오는 이메일은 오지 않습니다.

  • 안녕하세요.

    해당 문제는 저희도 직접 테스트를 해봐야 할 듯합니다.

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

    고맙습니다.

  • 원래 고객에게 가는 알림이 결제가 되었을 때도 가고, 취소되었을 때도 갔었는데,

    지금은 결제가 될 때는 안가고, 취소될 때만 갑니다.

    이 부분은 어디서 수정할 수 있을까요?

  • 말씀하신대로 해보았는데,

    undefined라는 메시지가 뜹니다. 메일은 안오고 결제는 이루어졌습니다.

  • 결제는 정상적으로 동작하고 있는지요?

    wp_mail_failed 액션은 메일을 전송 실패 시 페이지에 에러 메시지가 표시됩니다.

    즉, 결제가 이루어진 시점에 메일 발송에 실패했다면 페이지에 표시됩니다.

     

    cosmosfarm_members_subscription_request_pay 액션이 정상적으로 동작하고 있는지 확인하시려면

    아래의 코드를 테마 쪽 functions.php 파일에 추가해서 테스트해보시겠어요?

    add_action('cosmosfarm_members_subscription_request_pay', 'cosmosfarm_members_subscription_request_pay_test', 10, 2);
    function cosmosfarm_members_subscription_request_pay_test($order, $product){
    	echo '테스트입니다.'; exit;
    }

    해당 액션이 정상적으로 동작하고 있다면 결제 완료 후 페이지에

    "undefined" 라는 문구가 표시됩니다.

    고맙습니다.

  • 안녕하세요.

    알려주신 코드를 functions.php에 추가하여 다시 주문을 해보았지만 여전히 어드민에게 주문 성공 알림 이메일은 오지 않았는데, 고객에게는 "새로운 알림이 등록됐습니다." 메일은 갔습니다. 그리고 나이스페이먼츠 영수증 담긴 메일도 여전히 가지 않았습니다.

    그런데 어드민에게 가는 주문 성공 알림 이메일은 어딘가에서 작성을 해서 보내는 게 아니고 자동으로 발송이 되게 설정이 되어 있는 것인데, 

    "wp_mail_failed 액션을 사용하시면 메일 발송 실패 시 에러 메시지를 표시할 수 있습니다." 라고 말씀하신 부분에서 에러 메시지가 어디에 표시되는 것인지 모르겠습니다. 따라서 해당 에러 메시지가 어떻게 표시되었는지 모르겠습니다.

  • cosmosfarm_members_subscription_request_pay 액션 쪽은

    코드 상 문제없어 보입니다.

    서버를 바꾸기 전까지는 정상적으로 동작했다면

    현재 사용 중이신 서버 쪽의 문제일 수도 있습니다.

     

    wp_mail_failed 액션을 사용하시면 메일 발송 실패 시 에러 메시지를 표시할 수 있습니다.

    추가하신 코드 밑에 아래의 코드를 추가해서

    어떤 메시지를 표시하는지도 확인해보시겠어요?

    add_action('wp_mail_failed', 'my_mail_failed', 10, 1);
    function my_mail_failed($wp_error){
    	echo '<pre>';
    	print_r($wp_error);
    	echo '</pre>';
    	exit;
    }  

    고맙습니다.

  •     /* Email Notification - Order Completion */
        add_action('cosmosfarm_members_subscription_request_pay', 'my_subscription_request_pay', 10, 2);
    function my_subscription_request_pay($order, $product){
    	$to = 'order@midroen.com';
    	$title = '[미영알-결제완료] 새로운 주문 등록 알림';
    	$message = '미영알-새로운 주문이 등록되었습니다.';
    	
    	wp_mail($to, $title, $message);
    }
    ?>

    그리고 이 코드가 예전에 질문 드렸을 때 만들어주셔서 제가 functions.php에 마지막에 삽입한 것이고, 서버 엊그제 바꾸기 전까지는 주문 성공시 어드민에게 성공적으로 이메일을 보내주었었습니다.

  • <?php
    /**
     * This file can be used to validate that the WordPress wp_mail() function is working.
     * To use, change the email address in $to below, save, and upload to your WP root.
     * Then browse to the file in your browser.
     * 
     * For full discussion and instructions, see the associated post here:
     * http://b.utler.co/9L
     * 
     * Author:      Chad Butler
     * Author URI:  http://butlerblog.com/
     */
    
    /*  
    	Copyright (c) 2012-2015  Chad Butler
    	
    	This program is free software; you can redistribute it and/or modify
    	it under the terms of the GNU General Public License, version 2, as
    	published by the Free Software Foundation.
    
    	This program is distributed in the hope that it will be useful,
    	but WITHOUT ANY WARRANTY; without even the implied warranty of
    	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    	GNU General Public License for more details.
    
    	You should have received a copy of the GNU General Public License
    	along with this program; if not, write to the Free Software
    	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    
    	You may also view the license here:
    	http://www.gnu.org/licenses/gpl.html
    */
     
    // Set $to as the email you want to send the test to.
    $to = "info@midroen.com";
     
    // No need to make changes below this line.
     
    // Email subject and body text.
    $subject = 'wp_mail function test';
    $message = 'This is a test of the wp_mail function: wp_mail is working';
    $headers = '';
     
    // Load WP components, no themes.
    define('WP_USE_THEMES', false);
    require('wp-load.php');
     
    // send test message using wp_mail function.
    $sent_message = wp_mail( $to, $subject, $message, $headers );
    
    //display message based on the result.
    if ( $sent_message ) {
        // The message was sent.
        echo 'The test message was sent. Check your email inbox.';
    } else {
        // The message was not sent.
        echo 'The message was not sent!';
    }

    이게 mailtest.php 이고 이건 이제 보냈다고 메시지가 나옵니다.

    그리고 아래가 두번째로 말씀드린 플러그인으로 만든 php 파일 내용입니다.

    <?php
    /*
    Plugin Name: QnD wp_mail filter
    Plugin URI:  http://butlerblog.com/
    Description: A quick and dirty plugin to change the wp_mail "from" address to be something other than wordpress@mydomain.com.
    Version:     1
    Author:      Chad Butler
    Author URI:  http://butlerblog.com/
    License:     GPLv2
    */
    
    add_filter( 'wp_mail_from', 'qnd_mail_from' );
    /**
     * Changes the email address that WP puts in the 'from' address
     *
     * @param  string $email
     * @return string the email address to send from
     */
    function qnd_mail_from( $email )
    {
    	/* change the value below to the email address you want 
    	   wp_mail to send from
    	*/
    	return 'info@midroen.com';
    }
    
    add_filter( 'wp_mail_from_name', 'qnd_mail_from_name' );
    /**
     * Changes the email name that WP puts in the 'from' address
     *
     * @param  string $name
     * @return string the email name to send from
     */
    function qnd_mail_from_name( $name )
    {
    	/* change the value below to the email name you want 
    	   wp_mail to send from. For example, if you set the
    	   address above as john.doe@mydomain.com and you want
    	   the displayed name to be "John Doe" (i.e.
    	   John Doe <john.doe@mydomain.com>).  This could be
    	   a name like John Doe, or Administrator, or 
    	   Registrations, etc.  It could also be an email
    	   address, which would make the message come from
    	   myemail@mydomain.com <myemail@mydomain.com>
    	*/
    	return 'My Name';
    }
    ?>

     

  • 안녕하세요~^^

    실제 추가하신 코드가 어떻게 되시는지요?

    코드 상에 문제가 없다면

    메일을 보내는 기능은 서버 세팅에 의존하기 때문에

    플러그인 쪽에서는 해결이 불가능한 문제입니다.

     

    결제 시 카드 영수증은 PG사에서 이메일로 발송하고 있습니다.

    실제 저희 테스트 서버에서 나이스 페이로 결제 시

    영수증을 메일로 보내는 것을 확인했습니다.

     

    영수증을 별도로 확인하시려면 코스모스팜 회원관리 플러그인의 알림 페이지에서

    영수증 링크에서 매출전표를 확인하실 수 있으며 이메일로 발송하실 수 있습니다.

    고맙습니다.

  • 새로운 알림이 등록됐습니다. 라는 메일은 고객에게는 가고 있습니다. 

    https://imgur.com/a/b0aJtby

    그런데 여전히 나이스페이먼츠에서 가는 메일은 안가고 있고,

    어드민에게 가는 주문 성공시 통지 메일이 안가고 있습니다.

     

  • 그리고 나서 아래 링크에서 말하는 대로 php 파일 만들어서 플러그인에 추가하고 활성화했는데도 역시 마찬가지로 안됩니다.

    https://www.butlerblog.com/2011/07/14/changing-the-wp_mail-from-address-with-a-plugin/

  • 저희 고객지원 쪽 이메일로 확인해보니

    결제 시 메일을 정상적으로 전송하는 것을 확인했습니다.

    별 다른 설정이나 코드를 수정하지는 않았습니다.

    스팸 메일함에 있는 건 아닌지 다시 확인해보시겠어요?

     

    아래 코드들은 테스트용으로 안내해드렸기 때문에 현재는 지워뒀습니다.

    add_action('wp_mail_failed', 'my_mail_failed', 10, 1);
    function my_mail_failed($wp_error){
    	echo '<pre>';
    	print_r($wp_error);
    	echo '</pre>';
    	exit;
    }  
    add_action('cosmosfarm_members_subscription_request_pay', 'cosmosfarm_members_subscription_request_pay_test', 10, 2);
    function cosmosfarm_members_subscription_request_pay_test($order, $product){
    	echo '테스트입니다.'; exit;
    }

    고맙습니다.

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요