0

私のサイトで使用している連絡先フォームで動作するようにphpスクリプトを適応させようとしています。ページを表示しようとすると、次のエラーが表示されます。

解析エラー: 構文エラー、予期しないファイルの終わり

スクリプトをまとめて削除するとページが表示されるので、スクリプトが不完全なのではないでしょうか?

フォームとスクリプト コードは次のとおりです。

<form name="hongkiat" id="hongkiat-form" method="post" action="index.php">  
            <div id="wrapping" class="clearfix">  
                <section id="aligned">  
                    <input type="text" name="name" id="name" placeholder="Your name" autocomplete="off" tabindex="1" class="txtinput">  
                    <input type="email" name="email" id="email" placeholder="Your e-mail address" autocomplete="off" tabindex="2" class="txtinput">  
                    <input type="url" name="website" id="website" placeholder="Website URL" autocomplete="off" tabindex="3" class="txtinput">  
                    <input type="tel" name="telephone" id="telephone" placeholder="Phone number?(optional)" tabindex="4" class="txtinput">  
                    <textarea name="message" id="message" placeholder="Enter a cool message..." tabindex="5" class="txtblock"></textarea>  
                </section>  
            </div>
            <section id="buttons">  
                <input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset">  
                <input type="submit" name="submit" id="submitbtn" class="submitbtn" tabindex="7" value="Submit this!">  
                <br style="clear:both;">  
            </section>

            <?php
            $name = $_POST['name'];
            $email = $_POST['email'];
            $website = $_POST['website'];
            $telephone = $_POST['telephone'];
            $message = $_POST['message'];
            $from = 'web address here'; 
            $to = 'email here'; 
            $subject = 'Message from mh web';
            $body = "From: $name\n E-Mail: $email\n Website URL: $website\n Telehone: $telephone\n Message:\n $message";
            if ($_POST['submit'])  
            {                
            if (mail ($to, $subject, $body, $from)) 
            { 
                echo '<p>Your message has been sent!</p>';
            } 
            else 
            { 
                echo '<p>Something went wrong, go back and try again!</p>'; 
            } 
            ?>

        </form>
4

1 に答える 1

1

ブロックを閉じるには、}の前に別の右が必要です。コードが適切にインデントされているかどうかは、次のように簡単に確認できます。?>if($_POST['submit']){

        if ($_POST['submit'])  
        {                
            if (mail ($to, $subject, $body, $from)) 
            { 
                echo '<p>Your message has been sent!</p>';
            } 
            else 
            {  
            echo '<p>Something went wrong, go back and try again!</p>'; 
            }
        // oops!  missing }
        ?> 
于 2013-04-25T21:41:01.103 に答える