카테고리 없음
brevo 로 메일보내기 설정
해피위즈
2026. 8. 18. 21:30
/**
* Brevo(Sendinblue) 트랜잭션 이메일 간단 발송 스크립트
* https://api.brevo.com/v3/smtp/email
*/
// ==========================
// 1. 설정값 (본인 환경에 맞게 수정)
// ==========================
$apiKey = '토큰입력'; // Brevo API v3 키
$emailData = [
'sender' => [
'name' => '발신자',
'email' => 'brevo 등록한 메일',
],
'to' => [
[
'email' => '수신이메일',
'name' => 'Recipient Name',
],
],
'subject' => '메일 제목',
'htmlContent' => '<h1>안녕하세요</h1><p>Brevo API로 보낸 테스트 메일입니다.</p>',
];
// ==========================
// 2. 이메일 발송 함수
// ==========================
function sendBrevoEmail(string $apiKey, array $data): array
{
$url = 'https://api.brevo.com/v3/smtp/email';
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data, JSON_UNESCAPED_UNICODE),
CURLOPT_HTTPHEADER => [
'accept: application/json',
'content-type: application/json',
'api-key: ' . $apiKey,
],
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
return ['success' => false, 'error' => $error];
}
$decoded = json_decode($response, true);
return [
'success' => $httpCode >= 200 && $httpCode < 300,
'httpCode' => $httpCode,
'response' => $decoded ?? $response,
];
}
// ==========================
// 3. 실행
// ==========================
$result = sendBrevoEmail($apiKey, $emailData);
if ($result['success']) {
echo "✅ 메일 발송 성공!\n";
echo "Message ID: " . ($result['response']['messageId'] ?? 'N/A') . "\n";
} else {
echo "❌ 메일 발송 실패\n";
print_r($result);
}
--
하루발송 300건 무료
메일서버 지원하지 않은 웹호스팅에서
사용하기 좋은것 같아요