SMTP 테스트 코드
<?php
/*
* 파일명: test_smtp.php
* 기능: SMTP 메일 발송 테스트 (범용)
* 사용법:
* 1. 아래 경로를 프로젝트의 메일러 파일 경로로 수정
* 2. 받을 이메일 주소 수정
* 3. 브라우저에서 실행
*/
// ===================================
// 설정 영역 (프로젝트마다 수정)
// ===================================
// 메일러 파일 경로 (프로젝트에 맞게 수정)
require_once(__DIR__ . '/mail_config.php');
// 테스트 수신 이메일
$test_email = 'your-email@example.com';
// 테스트 메일 제목
$test_subject = '[테스트] SMTP 메일 발송 테스트';
// 테스트 메일 내용
$test_body = '
<div style="font-family: Arial, sans-serif; padding: 20px;">
<h2 style="color: #28a745;">✅ SMTP 메일 발송 테스트</h2>
<p>이 메일은 SMTP 설정이 정상 작동하는지 확인하기 위한 테스트 메일입니다.</p>
<div style="background: #f8f9fa; padding: 15px; border-radius: 5px; margin: 20px 0;">
<strong>발송 시간:</strong> ' . date('Y-m-d H:i:s') . '<br>
<strong>서버:</strong> ' . $_SERVER['SERVER_NAME'] . '<br>
<strong>PHP 버전:</strong> ' . PHP_VERSION . '
</div>
<p style="color: #666; font-size: 12px;">
메일이 정상적으로 수신되었다면 SMTP 설정이 올바르게 되어 있습니다.
</p>
</div>
';
// ===================================
// 테스트 실행
// ===================================
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SMTP 메일 발송 테스트</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.success {
background: #d4edda;
border: 1px solid #c3e6cb;
color: #155724;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.error {
background: #f8d7da;
border: 1px solid #f5c6cb;
color: #721c24;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.info {
background: #d1ecf1;
border: 1px solid #bee5eb;
color: #0c5460;
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
pre {
background: #f8f9fa;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>📧 SMTP 메일 발송 테스트</h1>
<div class="info">
<strong>📋 테스트 정보</strong><br>
수신 이메일: <?php echo htmlspecialchars($test_email); ?><br>
발송 시간: <?php echo date('Y-m-d H:i:s'); ?>
</div>
<?php
echo "<h3>🔄 메일 발송 중...</h3>";
$result = sendEmail($test_email, $test_subject, $test_body);
if ($result === true) {
echo '<div class="success">';
echo '<h3>✅ 메일 발송 성공!</h3>';
echo '<p><strong>' . htmlspecialchars($test_email) . '</strong>로 테스트 메일이 발송되었습니다.</p>';
echo '<p>📬 받은편지함 또는 스팸메일함을 확인해주세요.</p>';
echo '</div>';
} else {
echo '<div class="error">';
echo '<h3>❌ 메일 발송 실패</h3>';
echo '<p><strong>오류 내용:</strong></p>';
echo '<pre>' . htmlspecialchars($result) . '</pre>';
echo '</div>';
}
?>
<div class="info">
<strong>💡 참고사항</strong>
<ul>
<li>메일이 도착하지 않으면 스팸메일함을 확인하세요</li>
<li>네이버 메일의 경우 발송까지 1-2분 소요될 수 있습니다</li>
<li>테스트 완료 후 이 파일은 삭제하는 것을 권장합니다</li>
</ul>
</div>
</div>
</body>
</html>
언어: PHP