폼메일 다중체크 값 전송받기

폼메일 다중체크 값 전송받기

QA

폼메일 다중체크 값 전송받기

본문

덕서리님 폼메일 소스를 활용하여

아래 html폼과 php파일을 수정하여

메일을 받으려고 합니다.

 

다중 체크박스 값을 받아야 해서

여기저기 찾아보니 array로 넘겨 받으면 가능하다고 하셔서

아래와 같이 최종적으로 코드를 수정하였는데

메일을 전송하게 되면 아래 이미지처럼 문의내용에 다중체크 값이 아닌 array라고 값이 불러와져서 난감합니다 ㅜㅜ

3698692143_1595038712.0413.png

 

고수님들 해결방법 없을까요? 

 

아래 html과 php코드 올려봅니다 ㅜㅜ

제발 저에게 한줄기 빛이 되어주세요 흑흑

 

 


<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="http://hiforest.co.kr/bbs/content.php?co_id=service_center" class="">고객센터</a></li>
                  <li><a href="http://hiforest.co.kr/bbs/content.php?co_id=alliance" 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 class="multi_select">
                    <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[]" value="방송/협찬">방송/협찬<span style="margin-left:10px;display:inline-block;"></span>
                            <input type="checkbox" name="qna[]" value="유통/판매">유통/판매<span style="margin-left:10px;display:inline-block;"></span>
                            <input type="checkbox" name="qna[]" value="홍보/마케팅">홍보/마케팅<span style="margin-left:10px;display:inline-block;"></span>
                            <input type="checkbox" name="qna[]" value="제안">제안<span style="margin-left:10px;display:inline-block;"></span><br>
                            <input type="checkbox" name="qna[]" value="프로모션">프로모션<span style="margin-left:10px;display:inline-block;"></span>
                            <input type="checkbox" name="qna[]" value="대량구매">대량구매<span style="margin-left:10px;display:inline-block;"></span>
                            <input type="checkbox" name="qna[]" value="오프라인 미팅요청">오프라인 미팅요청<span style="margin-left:10px;display:inline-block;"></span>
                            <input type="checkbox" name="qna[]" 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>
 

 

 

 


<meta charset="utf-8">
<?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['company_name']) ||
!isset($_POST['phone_num']) ||
!isset($_POST['qna']) ||  // 이부분이 다중체크값!!!입니다.
!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
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
 
$list = $_POST['qna'];  // 이부분이 다중체크값!!!입니다.
echo $list[0];
echo $list[1];
 
$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($list)."\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


$list = implode(', ', $_POST['qna']); // ,로 결합. '사업제휴, 제안'처럼 결합됩니다.

 

+ implode()

- https://www.php.net/manual/en/function.implode.php

- http://docs.php.net/manual/kr/function.implode.php


// 첨부한 아래쪽의 소스(send_alliance.php 파일)에서 $list에 할당하는 부분입니다.
$list = $_POST['qna'];  // 이부분이 다중체크값!!!입니다.
echo $list[0];
echo $list[1];
// ↓
$list = implode(', ', $_POST['qna']); // ,로 결합. '사업제휴, 제안'처럼 결합됩니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 200
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT