<?php
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
// Get the data from the request
$requestData = json_decode(file_get_contents("php://input"), true);
// 인스턴스 생성
$phpmailer = new PHPMailer(true);
$phpmailer->SMTPDebug = SMTP::DEBUG_CONNECTION;
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.gmail.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'soamalert@gmail.com'; // 전송주체 이메일 주소
$phpmailer->Password = 'flhr vmds ryjn ixxp'; // 구글 2차 비밀번호 앱 인증번호로 교체
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Port = 587;
$phpmailer->setFrom('1234@gmail.com', 'SOAM Alert Manager'); // 전송주체의 이메일 주소 및 이름
$phpmailer->addAddress('5678@soamkim.com', 'dhjin'); // 받는 사람 주소
// 이메일 제목 및 본문
$phpmailer->isHTML(true);
$phpmailer->CharSet = 'UTF-8';
$phpmailer->Subject = '지메일 코드 대체 예보 알림 전송 시험';
$phpmailer->Body = '메일본문 내용 입력';
try {
// 이메일전송 및 확인
$phpmailer->send();
$response = ['status' => 'success', 'message' => 'Email Send Success'];
} catch (Exception $e) {
$response = ['status' => 'error', 'message' => 'Email Send Fail : ' . $phpmailer->ErrorInfo];
}
echo json_encode($response);
?>
현재 파일을 웹상에서 열면
echo json_encode($response);
에 의해 오류정보를 볼 수 있다.