안녕하세요.
덕서리님 소스
https://sir.kr/g5_skin/10486
위의 덕서리님 소스를 가지고 폼메일을 사용하고 있습니다.
소스도 간단하고 이상없이 메일로 잘 오는데
제가 어려움을 겪는 부분이
다중 셀렉박스 에서 선택한 값만 메일로 전송되게 하고 싶은데
선택적이 아니라 모든 셀렉박스를 체크해야만 메일이 가집니다. ㅜㅜ
select값에 따라 체크된 값만 메일로 전송될 수 있는 방법 없을까요?
고수님들 부탁드립니다.
메일 html
<div class="contact_form application">
<div class="row">
<div class="header_img">
<h4 class="title font_merri">Q&A</h4>
<p class="dec_p">하이포레스트 고객센터 입니다.<br>
무엇을 도와드릴까요?</p>
</div>
<div class="new-tab-2 tabs2">
<div class="menu-tab-wrap">
<div class="menu-tab">
<ul>
<li><a href="/bbs/content.php?co_id=application" class="">고객센터</a></li>
<li><a href="/bbs/content.php?co_id=application" class="on">제휴문의</a></li>
</ul>
</div>
</div>
</div>
<form name="contactform" method="post" action="send_alliance.php" class="main_form_wrap">
<table>
<tbody>
<tr>
<th scope="row_1"><label for="company_name">기업명<span class="required_star">*</span></label></th>
<td width="80%"><input id="companyinput" name="company_name" type="text" class="ipt" size="30" maxlength="50" placeholder="기업명을 입력해주세요." required=""></td>
</tr>
<tr>
<th scope="row_1"><label for="first_name">성함 / 직책<span class="required_star">*</span></label></th>
<td width="80%"><input id="nameinput" name="first_name" type="text" class="ipt" size="30" maxlength="50" placeholder="성함 / 직책을 입력해주세요." required=""></td>
</tr>
<tr>
<th scope="row_1"><label for="qna">문의 내용 <span class="small_p">[복수선택가능]</span><span class="required_star">*</span></label></th>
<td colspan="2">
<input type="checkbox" name="qna" value="사업제휴" >사업제휴 <span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_2" value="방송/협찬" >방송/협찬<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_3" value="유통/판매" >유통/판매<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_4" value="홍보/마케팅" >홍보/마케팅<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_5" value="제안" >제안<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_6" value="프로모션" >프로모션<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_7" value="대량구매" >대량구매<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_8" value="오프라인 미팅요청" >오프라인 미팅요청<span style="margin-left:10px;display:inline-block;"></span>
<input type="checkbox" name="qna_9" value="Other." >Other.
</td>
</tr>
<tr>
<th scope="row_1"><label for="phone_num">연락처 <span class="required_star">*</span></label></th>
<td width="80%"><input id="phoneinput" name="phone_num" type="text" class="ipt" size="30" maxlength="50" placeholder="연락처를 입력해주세요." required=""></td>
</tr>
<tr>
<th scope="row"><label for="email">이메일 주소 <span class="required_star">*</span></label></th>
<td><input id="mailinput" name="email" type="text" class="ipt" size="30" maxlength="80" placeholder="올바른 이메일 주소를 입력해주세요." required=""></td>
</tr>
<tr>
<th scope="row"><label for="comments">문의내용 <span class="required_star">*</span></label></th>
<td height="170" valign="bottom"><textarea id="coninput" name="comments" cols="50" rows="10" placeholder="문의내용을 남겨주세요." required=""></textarea></td>
</tr>
<tr>
<td height="40" colspan="2" style="text-align:center"><input type="submit" value="문의하기" class="btn_submit"><input name="재설정" type="reset" value="다시작성" class="btn_submit"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
send.php
<meta charset="utf-8">
<?php
if(isset($_POST['email'])) {
$email_to = "[email protected]"; // 문의메일 받는 사람 메일 주소
$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['company_name']) ||
!isset($_POST['phone_num']) ||
!isset($_POST['qna']) ||
!isset($_POST['qna_2']) ||
!isset($_POST['qna_3']) ||
!isset($_POST['email']) ||
!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
$company_name= $_POST['company_name']; // required
$phone_num = $_POST['phone_num']; // required
$qna = $_POST['qna'];
$qna2 = $_POST['qna_2'];
$qna2 = $_POST['qna_3'];
$email_from = $_POST['email']; // 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($company_name)."\n\n";
$email_message .= "성함 / 직책 : ".clean_string($first_name)."\n\n";
$email_message .= "문의내용 : ".clean_string($qna).",".clean_string($qna2).",".clean_string($qna3)."\n\n";
$email_message .= "연락처 : ".clean_string($phone_num)."\n\n";
$email_message .= "이메일 : ".clean_string($email_from)."\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개 / 댓글 1개
PHP는 잘 몰라서. 원코드는 send.php로 넘어 가는데
여기서는 action="send_alliance.php" 로 넘어가네요..
https://sir.kr/g5_tip/13330 를 사용해서 각각을 찍어보세요.. (디버깅하는데 도움이 됩니다. 제일 좋은 것은 xdebug라고 합니다.)
답변에 대한 댓글 1개
답변을 작성하려면 로그인이 필요합니다.
그리고 제가 디자이너라 올려주신 링크 내용은 이해를 하지 못했습니다
ㅜㅜ 죄송합니다.
(현재 메일이 아예 전송되지 않는 문제는 아니고
셀렉박스를 모두 체크해야지만 메일이 전송되고
몇 개만 골라 선택하면 메일이 가지 않는 것이 문제가 되고 있습니다 ㅜㅜ 흑)