Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

PHPMailer 에서 php mail() 함수 사용하여 메일 발송

2020-09-11 by 편리

이전 포스트에서 PHPMailer 를 이용해 메일 발송하는 것을 다뤘는데 일부 웹호스팅 환경에서는 smtp 사용할 경우 오히려 메일 발송이 실패하는 경우가 있고 php mail() 함수를 이용할 경우 정상적으로 발송되는 경우가 있어 smtp 사용 여부를 선택할 수 있도록 수정했다.

<?php
// PHPMailer SMTP
define('CM_SMTP_USE',    false);
define('CM_SMTP_HOST',   'smtp.server.com');
define('CM_SMTP_PORT',   '587');
define('CM_SMTP_AUTH',   true);
define('CM_SMTP_USER',   'user@server.com');
define('CM_SMTP_PASS',   'password');
define('CM_SMTP_SECURE', 'tls');
define('CM_SMTP_DEBUG',  false);

// Mail Sender
define('CM_SENDER_NAME',  '');
define('CM_SENDER_EMAIL', '');

config.php 파일엔 define('CM_SMTP_USE',    false); 를 추가했다. PHPMailer 클래스를 상속받아 구현된 MAILER 클래스의 코드를 아래처럼 수정했다.

<?php
/**
 * Mail send
 * type : text=0, html=1, text+html=2
 */

require __DIR__.'/PHPMailer/PHPMailerAutoload.php';

class MAILER extends PHPMailer
{
    public function __construct($exceptions = null)
    {
        parent::__construct($exceptions);

        if (CM_SMTP_USE === true) {
            $this->isSMTP();

            $this->Host = CM_SMTP_HOST;
            $this->Port = CM_SMTP_PORT;

            $this->Username   = CM_SMTP_USER;
            $this->Password   = CM_SMTP_PASS;
            $this->SMTPSecure = CM_SMTP_SECURE;

            $this->SMTPAuth   = CM_SMTP_AUTH;
        }

        if (CM_SMTP_DEBUG === true) {
            $this->SMTPDebug = 2;
            $this->Debugoutput = 'html';
        }

        $this->CharSet = 'UTF-8';
        $this->AltBody = '';
    }
}

자세한 수정 내역은 github 에서 확인할 수 있다.

Post navigation

Previous Post:

애드센스 sellers.json 게시 알림 해결

Next Post:

.env 파일 등 주요 설정파일 접근 제한하기

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes