테스트 사이트 - 개발 중인 베타 버전입니다

[폼메일]select값 구분선택후 여러메일로 보내기 채택완료

제이웬디 7년 전 조회 5,709

안녕하세요.  그누보드 게시판 관리자 메일로 받는 기능이 안되서 

아래 덕서리님 소스로 폼메일을 사용하려고 하는데요 소스도 간단하고 이상없이 메일로 잘 옵니다. 

 

그런데 한가지 사업부별로 선택해서 문의글을 작성하면 각각 담당자메일로 발송될수 있게 추가하고 싶은데요.

 

select값에 따라  '받을메일 주소'( $email_to = "test@gmail.com"; //받을 메일주소) 를  넘길 수 있는 방법이 있을까요?

 

고수님들 부탁드립니다. 

 

 

덕서리님 소스 https://sir.kr/g5_skin/10486

 

 

formmail.php

<form name="contactform" method="post" action="send.php">

<table></p>

<p><tr>

<th scope="row">구분</th>

<td><div class="navbar-form navbar-left form-group">

    <select name="subject" class="form-control">

        <option value="A사업부">A사업부</option>

        <option value="B사업부">B사업부</option>

        <option value="C사업부">C사업부</option>

        <option value="D사업부">D사업부</option>

    </select></div>

</td>

</tr></p>

<p><tr>

<th scope="row">

<label for="first_name">이름</label></th>

<td width="80%"></p>

<p><input name="first_name"  type="text" class="ipt" style="height:20px" size="30" maxlength="50" required >

</td>

</tr></p>

<p><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">

<input name="재설정" type="reset" value="다시작성" class="btn_submit"></td>

</tr>

</table>

</form>

 

 

 

 

 

send.php

 

 

<meta charset="utf-8">

<?php

if(isset($_POST['email'])) {

     

    

    $email_to = "test@gmail.com"; //받을 메일주소

    $email_subject = "[폼메일] 문의사항입니다.";

    $email_subject = '=?UTF-8?B?'.base64_encode($email_subject).'?=';</p>

<p>     

     

    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.
';

  }

    

  if(strlen($comments) < 2) {

    $error_message .= 'The Comments you entered do not appear to be valid.
';

  }

  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;

// 제목이 깨질경우 아래 캐릭터셋 적용</p>

<p>@mail($email_to, $email_subject, $email_message, $headers);  

?>

 

<!-- include your own success html here -->

 

<script>

alert ("메일이 발송되었습니다.\n빠른 시일안에 답변드리겠습니다.");

location.href='../';

</script>

 

<?php

}

?>

 

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

채택된 답변
+20 포인트
7년 전

send.php 상단 부분을 이렇게 바꾸면...

 

</p>

<p>$dept = $_POST['subject'];</p>

<p><span style="font-size:0.9em">if($dept == 'A사업부') { </span></p>

<p>$email_to = "<span class="privacy_hidden">a 메일주소</span>"</p>

<p><span style="font-size:0.9em"> } else if($dept == 'B사업부') { </span></p>

<p>$email_to = "<span class="privacy_hidden">b 메일주소</span>"<span style="font-size:0.9em"> </span></p>

<p><span style="font-size:0.9em"> } else if($dept == 'C사업부') { </span></p>

<p>$email_to = "<span class="privacy_hidden">c 메일주소</span>"</p>

<p><span style="font-size:0.9em"> } else { </span></p>

<p>$email_to = "<span class="privacy_hidden">d 메일주소</span>"</p>

<p><span style="font-size:0.9em"> } </span></p>

<p>

로그인 후 평가할 수 있습니다

답변에 대한 댓글 4개

그레이
7년 전
[code]
$dept = $_POST['subject'];
if($dept == 'A사업부') {
$email_to = 'A 메일주소';
} else if($dept == 'B사업부') {
$email_to = 'B 메일주소';
} else if($dept == 'C사업부') {
$email_to = 'C 메일주소';
} else {
$email_to = 'D 메일주소';
}
[/code]

이렇게 해보시면..
제이웬디
7년 전
와~ 감사합니다. 제가 세미콜론을 빠뜨렸네요 ;;
에고고 그레이님 너무 너무 감사합니다 ~ ^^
그레이
7년 전
제 답변에서 세미콜론이 빠진거죠..
(제 답변이 수시로 오타를 내서...ㅋ)
제이웬디
7년 전
그렇게라도 저에게 찾을 기회를 주셔서 감사합니다~
너무 감사드려요 그레이님~
복받으실꺼에요~ ^^

댓글을 작성하려면 로그인이 필요합니다.

:: . 첨부 화일 부분은 없나요?

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인