이메일로 인증번호 보내는 것 관련해서 질문 드립니다.
본문
안녕하세요? 항상 감사합니다.
로그인 페이지에서 이메일과 인증번호 입력란을 추가했습니다.
우선 이메일을 입력하고 인증번호 발송 버튼을 클릭하면 DB 에서 입력한 이메일이 존재하는지 확인하고 존재하지 않으면 입력란 아래에 "등록되지 않은 이메일 입니다." 라고 표시하고, 존재한다면 랜덤으로 번호를 생성해서 이메일로 보내고 해당 랜덤 번호를 g5_member 테이블에 insert 하려고 합니다.
그런데 $_POST['mb_email'] 부분 부터 이메일이 불러와 지지 않습니다. 어떻게 해야 하나요?
<div class="form-group has-feedback">
<label for="mb_email"><b>이메일</b><strong class="sound_only"> 필수</strong></label>
<div class="input-group">
<input type="text" name="mb_email" id="mb_email" value="" required class="form-control input-sm" size="20" maxLength="50">
<span class="input-group-btn">
<button type="button" class="btn btn-color" onclick="sendVerificationCode()">인증번호 발송</button>
</span>
</div>
<div id="errorText" class="text-danger"></div> <!-- 오류 메시지를 표시할 영역 -->
</div>
<?php
include_once(G5_LIB_PATH.'/mailer.lib.php');
if(isset($_POST['mb_email'])) {
$mb_email = $_POST['mb_email'];
$sql = "SELECT * FROM g5_member WHERE mb_email = '$mb_email'";
$row = sql_fetch($sql);
if(!$row['mb_email']) {
echo '<script>
var errorText = document.getElementById("errorText");
errorText.textContent = "등록되지 않은 이메일입니다.";
</script>';
} else {
$certification_number = rand(100000, 999999); // 랜덤 인증번호 생성
$sql2 = "UPDATE g5_member SET mb_certification_number = '$certification_number' WHERE mb_email = '$mb_email'";
sql_query($sql2);
// 이메일 발송 처리
$name = "youngrong"; // 보내는 사람 이름
$fmail = "*** 개인정보보호를 위한 이메일주소 노출방지 ***"; // 보내는 사람 이메일 주소
$to = $mb_email;
$subject = "인증번호 안내";
$content = "인증번호는 $certification_number 입니다.";
mailer($name, $fmail, $to, $subject, $content);
// 메일 발송 성공/실패에 따른 처리
if ($mailer_error) {
echo '<script>
var errorText = document.getElementById("errorText");
errorText.textContent = "메일 발송 중 오류가 발생했습니다.";
</script>';
} else {
echo '<script>
var errorText = document.getElementById("errorText");
errorText.textContent = "인증번호가 발송되었습니다.";
</script>';
}
}
}
?>