2016-03-21 5 views
0

私はブートストラップでスタイル付けされたフォームを作成し、フォームを機能的にする方法(情報が指定された電子メールに送信される電子メールで満たされている場合)作業。PHP - フォームの送信が機能しない

私はStackoverflowで多くのスレッドを読み込んでいますが、解決策を見つけることができませんでした。

php.iniファイルを正しく設定しても、mail()関数が動作しません。

以下は私のコードです。私はPHPで絶対初心者です。本当にありがとうございます!

<?php 

        function has_header_injection($str) { 
         return preg_match("/[\r\n]/", $str); 
        } 

        if (isset($_POST['contact_submit'])){ 

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

         if (has_header_injection($name)||($email)) { 
          die; 
         } 

        if (!$name || !$email || !$message) { 
         echo '<h2 class="success">All fields are required</h2> <a href="contact.php" class="btn btn-custom btn-sm">Try again</a>'; 
        }  

        $to = "[email protected]"; (this has my true email) 
        $subject = "$name sent you a message via example's contact form"; 
        $message = "Name: $name\r\n"; 
        $message .= "Email: $email\r\n"; 
        $message .= "Message:\r\n$msg"; 

        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; 
        $headers .= "From: $name <$email>\r\n";  
        $headers .= "X-Priority: 1\r\n";  
        $headers .= "X-MSMail-Priority: High\r\n\r\n"; 

        mail($to, $subject, $message, $headers); 



       ?> 

       <h2 class="success"> Thank you! Your project request is submitted. We will get back to you within 24 hours.</h2> 
       <p><a href="index.php" class="btn btn-custom btn-sm">&laquo; Go to home page</a></p> 

       <?php } else { ?> 



       <form action="" class="contact-form" id="contact-form" method="post" role="form"> 
        <div class="form-group"> 
         <label class="sr-only" for="name">Name</label> 
         <input type="text" class="form-control" id="name" name="name" required="" placeholder="Name"> 
        </div> 
        <div class="form-group"> 
         <label class="sr-only" for="email">Email</label> 
         <input type="email" class="form-control" id="email" name="email" required="" placeholder="Email"> 
        </div> 
        <div class="form-group"> 
         <textarea class="form-control" id="message" name="message" placeholder="Enter a brief description of your project" required=""></textarea> 
        </div> 
        <button type="submit" class="btn btn-custom" name="contact_submit">Send</button> 
       </form> 

       <?php } ?> 
+0

私は二重チェックしましたが、私の問題は依然として続きます –

答えて

2

ローカルホストで作業している場合は、メール機能が動作しない場合は、サーバーにコードを入力してください。

+0

私はlocalhostにいません。コードはウェブサイト上にあり、ライブです。 –

関連する問題