IT 관련,,/중요문자 적어두기

[WEB/PHP] 이메일(인증) 보내기 유효성 검증하기!!

IT깡패's 2021. 1. 1. 11:57
728x90
반응형
SMALL

안녕하세요~ IT깡패's입니다~ㅎㅎㅎ

html과 php를 사용해서 이메일 인증 폼과 유효성 검증에 대해서 알아보도록 하겠습니다!!

일단 html과 php는 서로 비슷한 느낌을 가진 언어로써, 둘 다 마크업언어라는 속성을 가지고 있습니다.

 

php로 회원가입을 할 때, 대체로 쓰는 인증으로는 휴대폰 인증과 이메일 인증이 있는데요~

그 중에 이메일 인증이 있는데요~

이 때, 기본적인 email폼인증과 메일보내기 등의 기능을 사용하는 방법이 있는 것을 알고 계신가요~

요새는 호스팅이나 사이트에서 기본적인 contact폼으로 많이 사용하는 방법 중 하나인데요.

한번 소스들을 살펴보도록 하겠습니다.

 

*이메일 폼(html)과  메일 보내기 설정(php)

회원가입에서 이메일 인증 버튼 창으로 들어오면 보이는 폼입니다~

일단 html을 사용했고요~

기본적인 자바스크립트로 간단한 유효성 검사도 하였습니다!!

 

sendmail.html - 기본 이메일 인증 폼을 가진 페이지 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>


<style>
td { color:#999999; font-size:12px; }
</style>

<script>
function check() {
	form = document.sendmail;
	if ( form.form_user.value == '' ) {
		alert('받는사람의 메일 주소를 입력해주세요.');
		form.form_user.focus();
		return false;
	}
	/*if ( form.subject.value == '' ) {
		alert('메일 제목을 입력해주세요.');
		form.subject.focus();
		return false;
	}*/

	form.submit();
}
</script>
</head>
<body>
<form name='sendmail' action='sendmail.php' method='post'>

	<table width='500' border='0' cellpadding='0' cellspacing='0' style='border:1px solid #999999;'>
		<tr height='30'>
			<td align='center' colspan='2' style='border-bottom:1px solid #999999;'>
				SendMail 테스트
			</td>
		</tr>
		<tr height='30'>
			<td width='100' align='right' style='border-bottom:1px solid #999999;'>
				받는 사람 : &nbsp; &nbsp;
			</td>
			<td style='border-bottom:1px solid #999999;'>
				<input type='text' name='form_user'>
			</td>
		</tr>
		<!--<tr height='30'>
			<td align='right' style='border-bottom:1px solid #999999;'>
				제목 :  &nbsp; &nbsp;
			</td>
			<td style='border-bottom:1px solid #999999;'>
				<input type='text' name='subject'>
			</td>
		</tr>
		<tr height='30'>
			<td align='right'>
				내용 :  &nbsp; &nbsp;
			</td>
			<td>
				<textarea name='content' style='width:380px; height:100px;'>메일 테스트</textarea>
			</td>
		</tr>-->
	</table>

	<table width='500' border='0' cellpadding='0' cellspacing='0'>
		<tr height='50'>
			<td align='center'>
				<input type='button' value='메일인증하기' onclick='check();'>
			</td>
		</tr>
	</table>
</form>
</body>
</html>

 

sendmail.php - 이메일 보내기 설정을 하는 페이지

<?php
$to = trim($_POST['form_user']); // 받는사람 메일주소 
$subject = '메일 인증';
$message = '메일 인증되셨습니다! 로그인 후 서비스를 이용해주시길 바랍니다.';


// html 메일을 보낼 때 꼭 이헤더가 붙어야한다.
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';

// Additional headers
//$headers[] = 'To: Kim<받는사람@gmail.com>';
$headers[] = 'From: webmaster<받는사람@gmail.com>';
//$headers[] = 'Cc: Kim1<참조인1@naver.com>,Kim2<참조인2@gmail.com>';
//$headers[] = 'Bcc: 숨은참조인3@gmail.com';


mail($to, $subject, $message, implode("\r\n", $headers));
echo "편지를 보냈습니다.";
	echo "<script language=javascript> alert('메일인증성공!'); location.replace('http://www.taeriview.com'); </script>";

	
?>

 

이제 웹에서 이메일 보내는 결과창을 확인해보도록 하겠습니다!!

세 단계로 보실 수가 있겠습니다~ㅎㅎㅎ

 

- 참고 링크


php 이메일(새회원) 검증 구현법 - https://code.tutsplus.com/ko/tutorials/how-to-implement-email-verification-for-new-members--net-3824

728x90
반응형
LIST