폼메일 메일 발송 실패

폼메일 메일 발송 실패

QA

폼메일 메일 발송 실패

본문

홈페이지 메인에

<? include_once(G5_PATH."/formmail.php") ?>

인클루드 시키고 g5 폴더 안에 formmail.php, send.php 업로드 했습니다..

 

문제는 이름, 연락처 등을 입력하고 전송버튼을 누르면

"메일발송을 실패하였습니다." 얼럿이 뜨는데 어떻게 해야할까요..


send.php 6번째 줄 메일 주소도 제대로 입력했고
환경설정 메일테스트도 정상적으로 발송되는거 확인했거든요..

php를 전혀 모르는 초보이다 보니 뭐가 잘못된건지 모르겠습니다..ㅠㅠ

 

 

formmail.php

 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>폼메일보내기</title>
<style>
table {width:100%; border-collapse: collapse; font-family:'NanumSquare', sans-serif;}
th { background:#ebebeb; color:#383838; text-align:center; font-size:14px;}
td {font-size:14px; color:#666}
</style>
</head>
<body>
    <form name="contactform" method="post" action="/g5/send.php">
        <table>
            <tr>
                <td>
                    <input name="first_name"  type="text" class="ipt" style="width:126px; height:30px;" maxlength="50" required placeholder=" NAME">
                    <input name="telephone"  type="text" class="ipt" style="width:200px; height:30px; margin-left:10px;" maxlength="111" required placeholder=" PHONE NUMBER">
                </td>
            </tr>
           
            <tr>
                <td>
                    <input name="email"  type="text" class="ipt" style="width:340px; height:30px; margin-top:10px;" maxlength="80" required placeholder=" E-MAIL">
                </td>
            </tr>
           
            <tr>
                <td valign="bottom">
                    <textarea  name="comments" cols="50" rows="10" style="width:340px; height:150px; margin-top:10px;" required placeholder=" MESSAGE"></textarea></td>
                </tr>
            <tr>
                <td colspan="2" style="text-align:center">
                    <input type="submit" value="SUBMIT" style="width:340px; margin-top:10px; border-radius:3px; border:none; background:#fbd117; font-family:'NanumSquare', sans-serif; font-size:18px; font-weight:900; color:#333;">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

 

 

 

send.php

 


<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['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.<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($first_name)."\n\n";
    $email_message .= "연락처 : ".clean_string($telephone)."\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
}
?>

이 질문에 댓글 쓰기 :

답변 2


function died($error) {
    // your error code can go here
    echo "<script> alert('$error');"; << 수정
    echo "history.go(-1);";
    echo "</script>";
    die();
}

현재 에러코드를 모두 "실패했습니다"로 제대로 출력되지 않고 있습니다.

이렇게 바꾸신후 결과를 다시 보셔야 할것 같습니다.

 

또한 mailer를 이용해서 발송하는 중입니다만...

lib\mailer.lib.php를 이용하신다면.

bbs\write_update.php 파일을 참고 하셔야 할듯 합니다.

아ㅠㅠ 바보같은 실수를 했었네요....
말씀하신 대로 오류 메시지 수정하고 테스트하니 입력한 메일주소가 틀렸다고 나오더라구요..
알고보니 테스팅한다고 폼에 입력한 이메일 주소를 한글로 아무렇게나 써놔서 그런거였어요ㅠㅠ
덕분에 해결했습니다 정말 감사합니다!

운영중인 서버에서 기본적인 mail함수가 지원이안되서 발송안될수도 있어요 확인해보세요

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

회원로그인

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