폼메일 send.php 소스 좀 봐주세요

폼메일 send.php 소스 좀 봐주세요

QA

폼메일 send.php 소스 좀 봐주세요

본문

send.php

 

 

<meta charset="utf-8">
<?php
if(isset($_POST['email1@email2'])) {
     
    
    $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['youhyung']) ||
        !isset($_POST['first_name']) ||
        !isset($_POST['company']) ||
        !isset($_POST['phone1']) ||
        !isset($_POST['phone2']) ||
        !isset($_POST['phone3']) ||
        !isset($_POST['email']) ||
        !isset($_POST['email1']) ||
        !isset($_POST['email2']) ||
        !isset($_POST['title']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }
    
    
    $youhyung = $_POST['youhyung']; // required
    $first_name = $_POST['first_name']; // required    
    $company = $_POST['company']; // required  
    $phone1 = $_POST['phone1']; // not required
    $phone2 = $_POST['phone2']; // not required
    $phone3 = $_POST['phone3']; // not required
    $phone = $phone1."-".$phone2."-".$phone3;
    $email1 = $_POST['email1']; // required
    $email2 = $_POST['email2']; // required
    //$email_from = $_POST['email']; // required
    $email_from = $_POST[$email1."@".$email2]; // required

    $title = $_POST['title']; // 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.<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($youhyung)."\n\n"; 
    $email_message .= "담당자 이름 : ".clean_string($first_name)."\n\n";
    $email_message .= "회사명 : ".clean_string($company)."\n\n";
    $email_message .= "이메일 : ".clean_string($email_from)."\n\n";
    $email_message .= "연락처 : ".clean_string($phone)."\n\n";
    $email_message .= "제목 : ".clean_string($title)."\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='../inquiry.php';
</script>
 
 
<?php
}
?>

 

 

formail.php

 

<tr>
<th scope="row"><span class="essential-icon">*</span> E-mail</th>
<!--<td>
<input name="email"  type="text" class="ipt" style="height:20px" size="30" maxlength="80" required >
</td>
-->
<td>
    <fieldset class="email-fieldset">
        <input type="text" class="write-input width20" name="email1" required> 
        <span class="hypen">@</span> 
        <input type="text" class="write-input width20" name="email2" required>
        <select name="email3" class="write-select width20" onchange="res();" >
            <option value="b">메일계정선택</option>
            <option value="a">직접입력</option>
            <option value="naver.com">naver.com</option>
            <option value="nate.com">nate.com</option>
            <option value="hanmail.net">hanmail.net</option>
            <option value="gmail.com">gmail.com</option>
            <option value="hotmail.com">hotmail.com</option>
            <option value="outlook.com">outlook.com</option>
            <option value="empal.com">empal.com</option>
            <option value="dreamwiz.com">dreamwiz.com</option>
            <option value="lycos.co.kr">lycos.co.kr</option>
            <option value="yahoo.co.kr">yahoo.co.kr</option>
            <option value="korea.com">korea.com</option>
            <option value="paran.com">paran.com</option>
        </select>
    </fieldset>
</td>
</tr>

 

 

 

 

소스좀 봐주세요

 

현재 메일폼을 2개로 나누어서 구성했는데요 

이렇게 하니깐 폼메일이 전송이 안됩니다

 

그런데 

주석처리 해논 소스 (아래소스)

<input name="email"  type="text" class="ipt" style="height:20px" size="30" maxlength="80" required >

 

이렇게 설정 하면 정상적으로 보내집니다 

 

아마 send.php 부분에 굻게 표시한 부분이 잘못 된거 같은데 어떻게 변경 해야 할지 모르겠어여 도와주세요

이 질문에 댓글 쓰기 :

답변 2

if(isset($_POST['email1@email2'])) { 이게 먹히나요??

제 생각엔 이메일의 위 내용이 문제가 되는것으로 보여지는데..

음..그냥 안전빵으로 

echo "<pre>";

print_r($_POST);

echo "</pre>";

exit;

로 해서 정상적으로 넘어오는 값이 무엇인지 확인 해보시고 이후 진행하시는것이 맞다고 판단됩니다.

toqurk 님께서 말씀해주신대로 데이터값이 어떻게 받아오는지 봤는데요

아마 if(isset($_POST['email'])) 이부분이 정상적으로 받아오지 못해서 그런거 같아요

현재 input 2개로 이메일을 받아오고 있어서

<input type="text" class="write-input width20" name="email1" required>
<span class="hypen">@</span>
<input type="text" class="write-input width20" name="email2" required>

이렇게요

근데 현재는

예) test @ naver.com 이렇게 받아와야 되는 데이터가
    test
    naver.com

이렇게 받아오네요 ....
email1과 email2를 합쳐서 email로 만들순 없을까요??

데이터 전달되어지는 변수 값 부분의 문제가 있는듯 하고

해당 널값 체크하는 변수 부분에도 email 파라메타가 존재하고 있습니다.

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

회원로그인

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