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

db에 입력값 저장 후 폼메일 전송 채택완료

vhdlsxm 4년 전 조회 7,327

안녕하세요! 

 

덕서리님 폼메일 보내기

https://sir.kr/g5_skin/10486

 

위 링크의 폼메일 스킨을 이용하여 신청 폼을 작성 시 지정된 메일 주소로 폼 메일이 전달되도록 하는 프로그램을 구현중입니다. 다만 폼메일이 전달 되기 전에 db에 입력 값이 저장되어야 하는데, 메일은 정상적으로 작동하는데 db에 저장이 되지 않습니다... db에 값을 insert 하는 구문을 따로 파일을 만들어 실행하면 제대로 값이 들어가는데.. 두 코드를 합치면 왜 db에 값이 들어가지 않는지 궁금합니다!ㅠㅠ

고수님들의 조언을 부탁드려요!

 

</p>

<p><?php</p>

<p>// db에 값 insert

include_once("./_common.php");

$first_name  = $_REQUEST[first_name];

$email   = $_REQUEST[email];

$telephone   = $_REQUEST[telephone];

$comments   = $_REQUEST[comments];

$pf_no1   = $_REQUEST[pf_no1];

$pf_no2   = $_REQUEST[pf_no2];

$pf_no3   = $_REQUEST[pf_no3];

$pf_time  = $_REQUEST[pf_time];

$pf_time  = $_REQUEST[pf_type];

$ip       = $_SERVER[REMOTE_ADDR];

$result=sql_query("insert into {$g5['phone_table']} (first_name,email,telephone,comments,ip,regdate,status) values ('$first_name','$email','$telephone','$comments','$ip',now(),0)");

// 

if($result) {</p>

<p>  if(isset($_POST['email'])) {</p>

<p>

    $email_to = "donna79337412@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();

    }</p>

<p>    // 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.');       

  }</p>

<p>    $first_name = $_POST['first_name']; // required

    $email_from = $_POST['email']; // required

    $telephone = $_POST['telephone']; // not required

    $comments = $_POST['comments']; // required</p>

<p>    $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 = "";</p>

<p>    function clean_string($string) {

      $bad = array("content-type","bcc:","to:","cc:","href");

      return str_replace($bad,"",$string);

    }</p>

<p>    $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";</p>

<p>

// create email headers

    $headers = 'From: '.$email_from;

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

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

    ?></p>

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

<p>    <script>

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

      location.href='../';

    </script></p>

<p>

    <?php</p>

<p>  }

} else { 

  alert("접수가 실패했습니다.");

  history.back();

  exit();

}</p>

<p>

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

답변 2개

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

sql 문제는, sql문을 별도로 출력해서 쿼리 -> 확인해 보는 것이 좋습니다.

</p>

<p>$sql = "insert into {$g5['phone_table']} (first_name,email,telephone,comments,ip,regdate,status) values ('$first_name','$email','$telephone','$comments','$ip',now(),0)";

$result = sql_query($sql);</p>

<p>echo $sql;</p>

<p>exit;</p>

<p>

 

같은 디렉토리에 _common.php 파일이 없거나,

$g5['phone_table'] 에 저장된 값이 없거나..

문제일 듯 합니다.

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

답변에 대한 댓글 1개

v
vhdlsxm
4년 전
_common.php 경로랑 위치가 잘못 되었던 거였네요ㅠㅠㅠ
조언 덕분에 문제 해결했습니다!
덕분에 칼퇴가 가능하겠네요! 감사합니다!!

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

먹고따블

$result=sql_query("insert into {$g5['phone_table']}  set first_name ='$first_name', email='$email', telephone='$telephone', comments='$comments', ip='$ip', regdate=now(), status='0'");

 

insert문을 확장형으로 쓰시는게 편할 거예요

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

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

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

로그인