-1

这是我在这里的第一个问题,我是 PHP 初学者,一直盯着这段代码试图找到错误,但我就是无法理解。

电子邮件联系表格:

<div id="newsletter">
        <h1>Contact Us</h1>
        <form method="post" action="global.footer.php">
            <p><input id="one" name="name" placeholder="name"></p>
            <p><input id="two" name="email" placeholder="email"></p>
            <p><textarea id="three" name="message" placeholder="type message here..."></textarea></p>
            <p><input id="submit" type="submit" name="submit" value="Submit"></p>
        </form> 
    </div>  

脚本:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: TangledDemo'; 
    $to = 'danajwright@gmail.com'; 
    $subject = 'Hello';

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>

<?php
if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, please try again.</p>'; 
            }
        } else {
            echo '<p>You need to fill in all required fields!!</p>';
        }

?>

任何帮助,将不胜感激!

4

4 回答 4

5

你得到了}开幕的结束if($_POST['submit']) {

于 2013-07-21T19:58:19.663 回答
1

你的第一个 if 没有关闭:

<?php
if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, please try again.</p>'; 
            }
        } else {
            echo '<p>You need to fill in all required fields!!</p>';
        }
}
?>
于 2013-07-21T19:58:29.890 回答
0

您必须if使用匹配的大括号关闭您的子句:

if ($_POST['submit']) {
   if ($name != '' && $email != '') {
      if (mail ($to, $subject, $body, $from)) { 
         echo '<p>Your message has been sent!</p>';
      }
      else { 
         echo '<p>Something went wrong, please try again.</p>'; 
      }
   }
   else {
      echo '<p>You need to fill in all required fields!!</p>';
   }
}
^ this brace must be added
于 2013-07-21T21:24:02.807 回答
0

你忘了在你的 php 结束时关闭。

<div id="newsletter">
        <h1>Contact Us</h1>
        <form method="post" action="global.footer.php">
            <p><input id="one" name="name" placeholder="name"></p>
            <p><input id="two" name="email" placeholder="email"></p>
            <p><textarea id="three" name="message" placeholder="type message here..."></textarea></p>
            <p><input id="submit" type="submit" name="submit" value="Submit"></p>
        </form> 
    </div>  
    <?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: TangledDemo'; 
    $to = 'danajwright@gmail.com'; 
    $subject = 'Hello';

    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
?>

<?php
if ($_POST['submit']) {
    if ($name != '' && $email != '') {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, please try again.</p>'; 
            }
        } else {
            echo '<p>You need to fill in all required fields!!</p>';
        }
        /* You forgot to close the : the below was missing good luck*/
        }

?>
于 2013-07-21T20:10:32.053 回答