Web 프로그램/PHP 응용 및 활용
Naver SMTP 기기 비밀번호 설정
Link2Me
2024. 5. 21. 22:42
네이버 STMP 메일 발송하기 위한 준비 과정이다.
2단계로 SMS 인증을 선택한 경우에는 SMTP 메일 발송을 위한 별도의 기기용 비밀번호를 추가로 설정해야 한다.
설정한 비밀번호를 구현한 코드에 넣어야 한다.
function email_send($to_email,$subject,$message){
$mail = new PHPMailer(true);
//$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->Charset = 'UTF-8';
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.naver.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'jsk005@naver.com'; //SMTP username
$mail->Password = ''; //SMTP password (기기 비밀번호)
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('jsk005@naver.com', '홍길동');
//foreach($recipients as $to_email){
$mail->addAddress($to_email); //Add a recipient
//}
$mail->addReplyTo('jsk005@naver.com', '홍길동');
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
}
|
728x90