2013-11-28 2 views
0

본인은 본인의 코드에서 누락 된 부분을 찾아 내려고 노력했습니다. 기본적으로 제출 버튼을 클릭하여 연락처 양식의 데이터를 보내면 기본적으로 나를 홈 페이지로 되돌리고 탭에 '페이지를 찾을 수 없음'이 표시됩니다. 여기 문의 양식을 수정하려고 시도했습니다.

여기
<?php 
$error=false; 
$sent=false; 
if(isset($_POST['submit'])) { 
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) { 
    $error = true; 
} else { 

$to = "[email protected]"; 

$name = trim($_POST['name']); 
$email = trim($_POST['email']); 
$message = trim($_POST['message']); 


$messages ="\r\n Name: $name \r\n Email: $email \r\n Message: $message"; 
$headers = "From:" . $name; 
$mailsent = mail($to, $subject, $message, $headers); 

if($mailsent){ 
    $sent= true; 
    } 
    } 
} 
?> 

내 마크 업 코드

<div class="col10"> 
<div class="contact_form"> 
<h2>Inquiries/Comments/Suggestions</h2> 
<form id="register-form" action="" method="post"> 

    <?php if($error == true) { ?> 
    <p class="error"> There are some misisng fields.</p> 
    <?php } if($sent == true) { ?> 
    <p class="sent">Thank you for sending your message</p><?php } ?> 

    <div class="contact-form"> 
    <input type="text" name="name" placeholder="Name"> 

    <input type="text" name="email" placeholder="Email"> 

    <textarea name="message" placeholder="Message"></textarea> 

    <label>Where did you learn about us?</label> 

    <select> 
     <option>Word of Mouth</option> 
     <option>Billboards</option> 
     <option>Roadshows</option> 
     <option>Sales agents</option> 
     <option>TV ads</option> 
     <option>Booths/Exhibits</option> 
     <option>Print Ads</option> 
     <option>Internet</option> 
     <option>Direct Mail</option> 
     <option>Flyer</option> 
     <option>Referral</option> 
     <option>Others</option> 
    </select> 

    <input type="submit" value="send" name="submit"> 


</form> 
</div> 
</div> 

</div> 
+0

시도 당신은 주제를 – Kalpit

+0

= ""행동에 파일 이름을 제공합니다. 나는 $ subject 값을 놓친 것 같아. –

+0

정의하십시오 속성 빈 조치가 필요하지 않습니다 –

답변

0

시도가

<from method="POST" action="contact.php"> 

대신

<form method="POST" action=""> 
을 확인하는 것입니다 내 코드입니다

그렇지 않으면 제거 행동 = "이메일"

+0

귀하의 솔루션은 여전히 ​​같은 결과를 시도 T_T – clestcruz

+0

는 동일한 파일에있는 귀하의 PHP 코드입니까? – Kalpit

+0

예. 내 PHP 코드는 동일한 파일 (contact-page.php)에 배치됩니다. – clestcruz

0

당신은 같은 폼에서 작업을 지정해야합니다

는 스크립트가 실행됩니다
<form id="register-form" action="your_file.php" method="post"> 

후 것을, 그래서 다음과 같은 출력을 할 수있다 " sended "또는 새 페이지로 리다이렉트합니다.

+0

PHP 코드가 같은 페이지 (contact-page.php)에 있다면? – clestcruz

+0

hmmm 액션을 비워두면 같은 페이지로 리다이렉트해야한다. 당신의 contact-page.php를 여기에 쓰거나이 action = "" 이 작동하지 않으면 .htaccess 파일이나 가상 호스트에 redirct가 있습니까? –

0

대신 빈을 떠나의 요청을 실행하는 데 책임이 action 속성에 경로를 쓰기이

<?php 
$error=false; 
if(isset($_POST['submit'])) { 
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) { 
    $error = true; 
} else { 

$name = trim($_POST['name']); 
$email = trim($_POST['email']); 
$message = trim($_POST['message']); 
$to = "[email protected]"; 

$headers=array(
     'MIME-Version: 1.0' . "\r\n", 
     'From: '.$to, 
     'Content-Type:text/html', 
     'Reply-To: [email protected]' 
    ); 
$subject = "your subject"; 

$messages ="\r\n Name: $name \r\n Email: $email \r\n Message: $message"; 

if (!mail($email,$subject,$messages,implode("\r\n",$headers))) { 
      mail($to, 'Error sending', 'The following order was not sent:&nbsp;'); 

     } 


} 
} 
?> 


<div class="col10"> 
<div class="contact_form"> 
<h2>Inquiries/Comments/Suggestions</h2> 
<form id="register-form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> 

    <?php if($error == true) { ?> 
    <p class="error"> There are some misisng fields.</p> 
    <?php } if($sent == true) { ?> 
    <p class="sent">Thank you for sending your message</p><?php } ?> 

    <div class="contact-form"> 
    <input type="text" name="name" placeholder="Name"> 

    <input type="text" name="email" placeholder="Email"> 

    <textarea name="message" placeholder="Message"></textarea> 

    <label>Where did you learn about us?</label> 

    <select> 
     <option>Word of Mouth</option> 
     <option>Billboards</option> 
     <option>Roadshows</option> 
     <option>Sales agents</option> 
     <option>TV ads</option> 
     <option>Booths/Exhibits</option> 
     <option>Print Ads</option> 
     <option>Internet</option> 
     <option>Direct Mail</option> 
     <option>Flyer</option> 
     <option>Referral</option> 
     <option>Others</option> 
    </select> 

    <input type="submit" value="send" name="submit"> 


</form> 
</div> 
</div> 

</div> 
1

같은 시도 할 수 있습니다. action 속성을 비워두면 기본 경로 (보통 홈 페이지)가 제출 경로로 간주됩니다.

<form id="register-form" action="./contact.php" method="post"> 

(./contact.php 양식 제출 요청을 실행하는) 책임 (상대 경로입니다 가정.)

0

사용 <?php echo $_SERVER['PHP_SELF']; ?> 행동.

<form id="register-form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
+0

동일한 결과. 또한 홈페이지로 리디렉션하고 브라우저의 탭에 "페이지를 찾을 수 없음"을 표시합니다. – clestcruz

+0

그래서 코드를 다시 확인하십시오. 귀하의 코드에는 스크립트에 헤더 기능이 포함되어 있다고 생각합니다. –

0
your problem is the name of the below html field : 

<input type="text" name="name" placeholder="Name"> 

Instead of giving name="name" try giving it name="your_name" 

And the from action = "<?php the_permalink(); ?>" 

Try the below code, that will work for you: 

<div class="col10"> 
<div class="contact_form"> 
<h2>Inquiries/Comments/Suggestions</h2> 
<form id="register-form" action="<?php the_permalink(); ?>" method="post"> 

    <?php if($error == true) { ?> 
    <p class="error"> There are some misisng fields.</p> 
    <?php } if($sent == true) { ?> 
    <p class="sent">Thank you for sending your message</p><?php } ?> 

    <div class="contact-form"> 
    <input type="text" name="your_name" placeholder="Name"> 

    <input type="text" name="email" placeholder="Email"> 

    <textarea name="message" placeholder="Message"></textarea> 

    <label>Where did you learn about us?</label> 

    <select> 
     <option>Word of Mouth</option> 
     <option>Billboards</option> 
     <option>Roadshows</option> 
     <option>Sales agents</option> 
     <option>TV ads</option> 
     <option>Booths/Exhibits</option> 
     <option>Print Ads</option> 
     <option>Internet</option> 
     <option>Direct Mail</option> 
     <option>Flyer</option> 
     <option>Referral</option> 
     <option>Others</option> 
    </select> 

    <input type="submit" value="send" name="submit"> 


</form> 
</div> 
</div> 

</div> 
관련 문제