0

嘿伙计们,我一生都无法弄清楚我在哪里出错了。当表单提交时,它会将其带到一个空白页面。没有错误或确认。只是空白。我假设这是一个语法错误,但由于某种原因我看不到它。你们有看到什么吗?这是我的表单代码:

<form method="POST" action="mailtest.php">

<label>Name<span class="req">*</span></label>
<input name="name" placeholder="Type Here">

<label>Email<span class="req">*</span></label>
<input name="email" type="email" placeholder="Type Here">

<label>Subject</label>
<input name="subjectf" placeholder="Type Here">

<label>Message<span class="req">*</span></label>
<textarea name="message" placeholder="Type Here"></textarea>

<input class="submit" name="submit" type="submit" value="">
<span class="right" style="color:red">* represents a mandatory field.</span>
</form>

这是我在 mailtest.php 页面上的 php 脚本:

<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = $_POST['name'];
    $to = 'rkoolman@bellsouth.net'; 
    $subject= 'new enquiry on website';
    $subjectf= $_POST['subjectf'];  
    $body = "From: $name\n E-Mail: $email\n Subject: $subjectf\n Message:\n $message";

    if ($_POST['submit']) {
    if ($name != '' && $email != '' && $message != '') {         
            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>'; 
        } 
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
?>
4

2 回答 2

1

您应该始终首先检查表单是否已提交,以便

删除if ($_POST['submit'])并将其放在脚本的顶部..

你也应该检查是否$_POST["submit"]设置了..脚本应该是这样的:

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

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = $_POST['name'];
    $to = 'test@test.com'; 
    $subject= 'new enquiry on website';
    $subjectf= $_POST['subjectf'];  
    $body = "From: $name\n E-Mail: $email\n Subject: $subjectf\n Message:\n $message";


    if ($name != '' && $email != '' && $message != '') {         
            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>'; 
        } 
    } else {
        echo '<p>You need to fill in all required fields!!</p>';
    }
}
于 2013-05-02T02:34:53.463 回答
0

将您的提交输入值设置为提交

<input class="submit" type="submit" name="submit" value="submit">
于 2013-05-02T02:30:13.743 回答