【问题标题】:Trying to adapt a simple php contact form script尝试改编一个简单的 php 联系表单脚本
【发布时间】:2013-04-25 21:38:59
【问题描述】:

我正在尝试调整一个 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>

【问题讨论】:

    标签: php forms contact


    【解决方案1】:

    您需要在?&gt; 之前再添加一个},以关闭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 }
            ?> 
    

    【讨论】:

      猜你喜欢
      • 2011-08-27
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      相关资源
      最近更新 更多