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

폼메일 수신자 추가 가능한가요?? 채택완료

창쇼 4년 전 조회 2,356

폼메일 받아서 수정해 쓰려고 하는데. 

수신자(받는사람) 이메일이 하나밖에 안되는데 추가 하는 방법이 있나요??

이것저것 하는데 안되네요 ;;;

 

</strong></p>

<p>$to = 'informant@example.co.kr';</p>

<p>$to = 'informant@example.co.kr, informant2@example.co.kr'; // 안됨..</p>

<p>$to = 'informant@example.co.kr','informant2@example.co.kr'; //오류</p>

<p><strong>

 

</strong></p>

<p><?php

header("Content-Type: text/html; charset=UTF-8");

 

// 빈 필드가 있는지 확인하는 구문

if(empty($_POST['name'])          || // post로 넘어온 name값이 비었는지 확인

  empty($_POST['message']))    // message값이 비었는지 확인

   {

    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <script>

         window.alert('제목 혹은 본문을 작성해 주세요. ');

         history.go(-1);

         </script>";

    return false;

   }

// Cross-Site Scripting (XSS)을 방지하는 시큐어코딩

// strip_tags() -> 문자열에서 html과 php태그를 제거한다

// htmlspecialchars() -> 특수 문자를 HTML 엔터티로 변환

// 악의적인 특수문자 삽입에 대비하기 위함

 

$name = strip_tags(htmlspecialchars($_POST['name']));

$message = strip_tags(htmlspecialchars($_POST['message']));

    

// 이메일을 생성하고 메일을 전송하는 부분 아래 발신자 수신자 부분을 기입해 주세요

$to = 'informant@example.co.kr'; // 받는 측의 이메일 주소를 기입하는 부분

$from = 'informant';

$email_subject = " $name"; // 메일 제목에 해당하는 부분

$email_body = "본 메일은 한국회사 사원의 소리에서 전송된 이메일입니다.\n\n"."세부내용은 다음과 같습니다.\n\nSubject: $name\n\nMessage:\n$message";

$headers = "From : $from"; // 답장 주소

 

mail($to,'=?UTF-8?B?'.base64_encode($email_subject).'?=',$email_body, $headers);</p>

<p> if (!$name)

    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <script>

         window.alert('메일 발송이 실패하였습니다. ');

         history.go(-1);

         </script>";

  else

    echo "         <script>

         window.alert('메일이 정상적으로 발송되었습니다.');

         history.go(-1);

         </script>";</p>

<p>?></p>

<p><strong>

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

답변 2개

채택된 답변
+20 포인트

배열 및 for 사용

아래 주소에서 문자보내는방법 참고

https://sir.kr/g5_tip/15091

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

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

창쇼
4년 전

아래 처럼 수정하니까 되네요..

그런데 네이버만 가고, 다음이나 지메일은 안가는 이유를 모르겠네요 ㅎ

 

</strong></p>

<p>$to = '이메일'; // 기존</p>

<p>$to = '이메일, 이메일'; //수정</p>

<pre>
<strong>
로그인 후 평가할 수 있습니다

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

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

로그인