폼메일에 개인정보 체크시에만 전송
본문
덕서리 님 것으로 폼메일을 적용하였습니다!
폼에 개인정보 동의 내용을 추가한 후 체크 시에만 전송이 되고, 체크가 안될 시 전송이안되고 경고창이 뜨도록 하고싶습니다 ㅜㅜ html부분에 체크박스는 추가해놓았는데 php 부분에는 어떤 코드를 추가하고 수정해야할까요... 도와주세요...
<form name="contactform" method="post" action="send.php">
<table>
<tr>
<th scope="row">
<label for="first_name">이름</label></th>
<td width="100%">
<input name="first_name" type="text" class="ipt" style="height:20px" size="30" maxlength="50" required >
</td>
</tr>
<tr>
<th scope="row">
<label for="email">이메일 주소</label></th>
<td>
<input name="email" type="text" class="ipt" style="height:20px" size="30" maxlength="80" required >
</td>
</tr>
<tr>
<th scope="row">
<label for="telephone">연락처</label></th>
<td>
<input name="telephone" type="text" class="ipt" style="height:20px" size="30" maxlength="30" required >
</td>
</tr>
<tr>
<th scope="row">
<label for="comments">문의내용</label></th>
<td height="170" valign="bottom">
<textarea name="comments" cols="50" rows="10" style="width:95%" required ></textarea></td>
</tr>
<tr>
<td height="40" colspan="2" style="text-align:center">
<input type="submit" value="문의하기" class="btn_submit">
</tr>
</table>
</form>
<div class="agree-box">
<h3>*개인정보 수집 및 이용에 관한 안내</h3>
<ul>
<li>''는 문의하는 기업 및 개인을 대상으로 아래와 같이 개인정보를 수집하고 있습니다.</li>
<li>1. 수집 개인정보 항목 : 성명, 메일주소, 전화번호, 회사명, 홈페이지 주소, 팩스번호, 주소</li>
<li>2. 개인정보의 이용기간 : 모든 검토가 완료된 후 3개월간 이용자의 조회를 위하여 보관하며, 이후 해당정보를 지체 없이 파기합니다.</li>
<li>3. 그 밖의 사항은 개인정보취급방침을 준수합니다.</li>
</ul>
<label><input type="checkbox" name="U_checkAgreement" value="" id="U_checkAgreement">개인정보 제3자 제공에 동의합니다.(미동의시 신청불가)</label>
</div>
<?php
if(isset($_POST['email'])) {
$email_to = "*** 개인정보보호를 위한 이메일주소 노출방지 ***";
$email_subject = "[폼메일] 문의사항입니다.";
$email_subject = '=?UTF-8?B?'.base64_encode($email_subject).'?=';
function died($error) {
// your error code can go here
echo "<script> alert('메일발송을 실패하였습니다.');";
echo "history.go(-1);";
echo "</script>";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "이름 : ".clean_string($first_name)."\n\n";
$email_message .= "이메일 : ".clean_string($email_from)."\n\n";
$email_message .= "연락처 : ".clean_string($telephone)."\n\n";
$email_message .= "문의사항 : ".clean_string($comments)."\n\n";
// create email headers
$headers = 'From: '.$email_from;
// 제목이 깨질경우 아래 캐릭터셋 적용
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<script>
alert ("메일이 발송되었습니다.\n빠른 시일안에 답변드리겠습니다.");
location.href='../';
</script>
<?php
}
?>
답변 1
<!-- <form name="contactform" method="post" action="send.php"> -->
<form name="contactform" method="post" action="send.php" id="contactform">
<!-- <input type="checkbox" name="U_checkAgreement" value="" id="U_checkAgreement"> -->
<input type="checkbox" name="U_checkAgreement" value="" id="U_checkAgreement" form="contactform" required>
답변을 작성하시기 전에 로그인 해주세요.