PHP:邮件表单无法正确提交

时间:2015-10-09 17:23:59

标签: php html forms submit form-submit

我在网站上有一个没有提交任何信息的HTML表单。 HTML文件和表单的PHP文件位于同一目录中,当我尝试提交表单时,它只需要website_name/mail.php,我就不会收到任何电子邮件。

我查看了堆栈并用google搜索了它,大部分时间都是因为字段中的name属性丢失了,但我在那里有它们。我将不胜感激任何可以帮助我解决这个问题的帮助或意见。

这是HTML表单的代码部分:

<form action="mail.php" method="POST">
<br style="clear:both">
    <h3>Contact Us Today!</h3>
    <div class="form-group">
    <input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
    </div>
    <div class="form-group">
    <input type="text" class="form-control" id="email" name="email" placeholder="Email" required>
    </div>
    <div class="form-group">
    <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number" required>
    </div>
    <div class="form-group">
    <input type="text" class="form-control" id="subject" name="subject" placeholder="Subject" required>
    </div>
    <div class="form-group">
    <textarea class="form-control" type="textarea" id="message" placeholder="Message" maxlength="140" rows="7"></textarea>
    <span class="help-block"><p id="characterLeft" class="help-block "></span>
    </div>

    <button type="submit" id="submit" name="submit" class="btn-primary  btn-block">Submit Form</button>
</form>

这是我的php表单的代码,名为mail.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent= "From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "cesarm2333@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

当我提交此内容时,我只会在网址名称/ mail.php上看到一个白页 它是从we​​bsiteName / index.php

重定向的

2 个答案:

答案 0 :(得分:0)

我注意到在表单中,其中一个字段名称为mobile,但PHP代码试图获取$_POST['phone']

这可能是一个原因

答案 1 :(得分:0)

您在mail.php中没有使用过的输入字段很少。这可能是其中一个原因。 使用此代码。

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['mobile'];
$message = $_POST['message'];
$formcontent= "From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "cesarm2333@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>