---Before sort---
6.4 4.0 2.0
4.0 2.0 4.0
1.0 3.0 1.0
---After sort---
1.0 2.0 1.0
4.0 3.0 2.0
6.4 4.0 4.0
HTML
/ *主题和电子邮件变量* /
HTML:
<form class="contact_form" action="php/mail.php" method="post" name="contact_form">
<ul>
<li>
<label for="name">Name*</label>
<input type="text" placeholder="Your Name" required />
</li>
<li>
<label for="name">Email*</label>
<input type="email" name="email" placeholder="Your email address" required />
<span class="form_hint">Proper format "name@something.com"</span>
</li>
<li>
<label for="name">Website</label>
<input type="url" name="website" placeholder="Your website" required pattern="(http|https)://.+"/>
<span class="form_hint">Proper format "http://someaddress.com"</span>
</li>
<li>
<label for="message">Message:</label>
<textarea rows="6" cols="40" name="message" ></textarea>
</li>
<li>
<button class="submit" type="submit">Send</button>
</li>
</ul>
</form>
答案 0 :(得分:1)
我认为你错了,改变了
$headers = "From: $email\r\n";
到
$headers = "From: $emailField\r\n";
请记住验证$ emailField以避免注入!
更新:现在我可以看到表单的实际HTML,但是存在一些问题。
我认为for
需要和ID字段,因此您应该向表单中的每个字段添加一个。
您还忘记在名称文字字段中设置name
。
让我们在名称字段中添加name
属性,并添加ID
字段(也应该为其他字段完成):
<label for="name">Name*</label>
<input type="text" placeholder="Your Name" required />
到
<label for="name">Name*</label>
<input type="text" id="name" name="name" placeholder="Your Name" required />
$_POST['Name']
是区分大小写的,因此您应该更改代码,以使变量与html中的名称匹配。
例如:
$nameField = $_POST['Name'];
应该是
$nameField = $_POST['name'];
答案 1 :(得分:1)
还有更多问题,所以:
name
属性$_POST['name'] !== $_POST['Name']
)中区分大小写。这就是您收到空白字母的原因for
属性必须与输入ID
更新的代码:
<form class="contact_form" action="php/mail.php" method="post" name="contact_form">
<ul>
<li>
<label for="Name">Name*</label>
<input type="text" id="Name" name="Name" placeholder="Your Name" required />
</li>
<li>
<label for="Email">Email*</label>
<input type="email" name="Email" id="Email" placeholder="Your email address" required />
<span class="form_hint">Proper format "name@something.com"</span>
</li>
<li>
<label for="Website">Website</label>
<input type="url" id="Website" name="Website" placeholder="Your website" required pattern="(http|https)://.+"/>
<span class="form_hint">Proper format "http://someaddress.com"</span>
</li>
<li>
<label for="Message">Message:</label>
<textarea rows="6" id="Message" cols="40" name="Message" ></textarea>
</li>
<li>
<button class="submit" type="submit">Send</button>
</li>
</ul>
</form>
答案 2 :(得分:0)
将$nameField = $_POST['Name'];
$emailField = $_POST['Email'];
$website = $_POST['Website'];
$messageField = $_POST['Message'];
放在帖子函数中。验证后$_post
不为空。在表格提交。