【发布时间】:2016-01-07 17:43:44
【问题描述】:
我在一个没有提交任何信息的网站上有一个 HTML 表单。表单的 HTML 文件和 PHP 文件在同一个目录中,当我尝试提交表单时,它只是将我带到 website_name/mail.php 并且我没有收到任何电子邮件。
我查看堆栈并用谷歌搜索它,大部分时间是因为字段中的名称属性丢失,但我在那里有它们。我将不胜感激任何可以帮助我解决此问题的人的帮助或意见。
这是我的 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>
这是我的名为 mail.php 的 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>";
?>
当我提交这个时,我只在 url websiteName/mail.php 看到一个白页 从 websiteName/index.php
重定向【问题讨论】:
-
将错误报告添加到文件顶部,紧跟在打开 PHP 标记之后,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);然后是其余代码,看看它是否会产生任何结果。 -
是的,它成功了!我必须修复一些彼此不对应的变量名和一些根本没有使用的变量名,但这使得表单提交到我的电子邮件。非常感谢
-
不客气,很高兴它成功了。
标签: php html forms submit form-submit