2014-11-17 2 views
0

이메일 주소로 세부 정보/메시지를 보내야하는 페이지에 문의 양식이 있습니다. http://tedsrestaurant.com/index-working.html문의 양식이 작동하지 않음 (PHP)

HTML

<form id="contact-form" class="row style1" action="#" method="post"> 
    <div class="col-xs-12 col-sm-4"> 
     <div class="form-group"> 
      <input name="name" type="text" id="name" placeholder="Your name" required /> 
     </div> 
     <div class="form-group"> 
      <input name="number" type="text" id="number" placeholder="Your number" required /> 
     </div> 
     <div class="form-group"> 
      <input name="email" type="email" id="email" placeholder="Your e-mail" required /> 
     </div> 
    </div> 

    <div class="col-xs-12 col-sm-8"> 
     <textarea name="message" rows="4" class="h130" id="message" placeholder="Write your message..." required></textarea> 
    </div> 

    <div class="clear"></div> 

    <div class="col-md-9"><p>* When booking the <strong>Food Truck</strong>, please write date, time and number of guests into your message.</p></div> 
    <div class="col-md-3 right"> 
     <input class="submit btn" type="submit" value="Send a message" /> 
     <input class="modal btn hidden" type="button" value="Send a message" name="" data-toggle="modal" data-target="#modalBox" /> 
    </div> 

    <!-- Modal window --> 
    <div class="modal fade bs-modal-md" id="modalBox" tabindex="-1" role="dialog" aria-hidden="true"> 
     <div class="modal-dialog modal-md"> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
        <h4 class="modal-title" id="myModalLabel">Contact form</h4> 
       </div> 
       <div class="modal-body"></div> 
       <div class="modal-footer"> 
        <button type="button" class="btn right" data-dismiss="modal">Close</button> 
       </div> 
      </div> 
     </div> 
    </div> 
</form> 

그리고 PHP는 다음과 같습니다 : 당신은 여기를 볼 수 있습니다 (이것은 바닥 글입니다)

<?php 

//******** Email settings ********// 
//your email 
$email_to = "[email protected]"; 
//subject of email 
$email_subject = "This is a message"; 
//message after success send mail 
$email_send = "<div class='alert alert-success'> 
<strong>Contact form was sent successfully.</strong> 
<br/>Thank you for contacting us. We will be in touch with you very soon.</div>"; 

if($_POST) { 
    //******** Email data ********// 
    $cust_name = $_POST['name']; 
    $cust_number = $_POST['number']; 
    $cust_email = $_POST['email']; 
    $cust_message = $_POST['message']; 

    $header = "From:" . $cust_email . "\r\n"; 
    $header .= 'MIME-Version: 1.0' ."\r\n"; 
    $header .= 'Content-Type: text/html; charset=UTF-8' . "\r\n"; 
    $body = "<strong>Customer email:</strong> " . $cust_email . "<br/>"; 
    $body .= "<strong>Customer number:</strong> " . $cust_number . "<br/>"; 
    $body .= "<strong>Customer name:</strong> " . $cust_name . "<br/>"; 
    $body .= "<strong>Message:</strong> " . $cust_message; 

    if($cust_name && $cust_number && $cust_email && mail($email_to, $email_subject, $body, $header)) { 
     echo $email_send; 
     echo '<script>$("#contact-form").each(function(){ 
        this.reset(); 
       }); 
       </script>'; 
    } else { 
     echo "<div class='alert alert-warning'><strong>Error sending mail. Please fill the contact form correctly or contact website administrator.</strong></div>"; 
    } 

} 

은 모든 올바른 보입니까? 참고로 사이트의 PHP에는 [email protected]이 아닌 실제 이메일 주소가 있습니다. 제출 버튼을 누르면 동일한 페이지로 이동하지만 아무 것도 내 이메일에 오지 않습니다.

+0

어떤 실수가 났습니까? ??? – Dinesh

+0

'action = "#"'?. 'if ($ _ POST) {'를'if ($ _ SERVER [ 'REQUEST_METHOD'] == "POST")'로 변경하십시오. –

+0

이전에는 이것을 확인해야했지만 Chrome 및 Safari에서는 제대로 작동하지만 Firefox에서는 작동하지 않습니다. 이것은 나에게 이상한 것 같다. – Bove

답변

0

받는 출력은 무엇입니까? email_sent 또는 오류 메시지?

내가 맞지 않을 경우 if($_POST) 대신 if($_SERVER['REQUEST_METHOD'] == "POST")을 사용하여 요청 유형이 POST인지 확인하고 계속 진행해야합니다.

+0

원래 코드는 Chrome과 Safari에서 잘 작동하지만 위에서 언급 한 대체 코드와 마찬가지로 어떤 이유로 든 Firefox에서 제대로 작동하지 않습니다. Firefox에서 제출을 클릭하면 팝업이 표시되지 않습니다. 내 캐시를 여러 번 정리했습니다. 행운은 없습니다. – Bove

+0

팝업이 Firefox에서 표시되지 않지만 여전히 메일을 수신합니까? – bSaraogi

+0

아니요, Firefox에서 양식을 작성할 때 아무 것도받지 못합니다. – Bove

0

SwiftMailer을 사용하는 것이 좋습니다.

require_once 'lib/swift_required.php'; 

// Create the Transport 
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25) 
    ->setUsername('your username') 
    ->setPassword('your password') 
    ; 

/* 
You could alternatively use a different transport such as Sendmail or Mail: 

// Sendmail 
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs'); 

// Mail 
$transport = Swift_MailTransport::newInstance(); 
*/ 

// Create the Mailer using your created Transport 
$mailer = Swift_Mailer::newInstance($transport); 

// Create a message 
$message = Swift_Message::newInstance('Wonderful Subject') 
    ->setFrom(array('[email protected]' => 'John Doe')) 
    ->setTo(array('[email protected]', '[email protected]' => 'A name')) 
    ->setBody('Here is the message itself') 
    ; 

// Send the message 
$result = $mailer->send($message); 
관련 문제