-5

我创建了一个连接的 HTML 和一个 php 文件: html 表单中的数据必须发送到我的电子邮件地址。

我已将带有 php 脚本的 html 文件上传到我在 000webhost.com 上的目录

当我测试表单时,当我想提交表单时,000webhost 告诉我我的 php 脚本的第 6 行有错误。

任何人都可以帮我找到错误并修复它吗?

我的 HTML 文件:.inputtext { 宽度:300px; 高度:30px;}

<!--
.button {
display:block;
font-weight:bold;
font-size:18px;
font-family:Calibri;
color:#009933;
background-color:#ffffff;
width:150px;
text-align:center;
padding:4px;
border-top: 1px solid #b2b2b2;
border-bottom: 1px solid #b2b2b2;
border-left: 1px solid #b2b2b2;
border-right: 1px solid #b2b2b2;

}
-->
</style></head>

<form action="mail.php" method="POST">
<div align=center>
<Table border=0><tr><td>
<table border=0>

<tr>
<td valign=top><h3><font face=calibri color=#009933>Name<font face=calibri color=red>*</font></h3></td>
<td valign=top><input type="text" name="name" class=inputtext></td>
</tr>

<tr>
<td valign=top><font face=calibri color=#009933><h3>Email address<font face=calibri color=red>*</font></h3></td> 
<td valign=top><input type="text" name="email"class=inputtext></td>
</tr>

<tr>
<td valign=top><font face=calibri color=#009933><h3>Select your gender<font face=calibri color=red>*</font></h3></font></td>
<td valign=top><font face=calibri><input type="radio" name="gender" value="Male"> Male&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=radio name=gender value=Female> Female</font></td>
</tr>

<tr>
<td valign=top><font face=calibri color=#009933><h3>Select your age<font face=calibri color=red>*</font></h3></font></td>
<td valign=top><select name="age" size=1>
                 <option value=Below 18>Below 18</option>
                 <option value=18>18</option>
                 <option value=19>19</option>

                 <option value=20>20</option>
                 <option value=21>21</option>
                 <option value=22>22</option>
                 <option value=23>23</option>
                 <option value=24>24</option>
                 <option value=25>25</option>
                 <option value=26>26</option>
                 <option value=27>27</option>
                 <option value=28>28</option>
                 <option value=29>29</option>

                 <option value=30>30</option>
                 <option value=31>31</option>
                 <option value=32>32</option>
                 <option value=33>33</option>
                 <option value=34>34</option>
                 <option value=35>35</option>
                 <option value=36>36</option>
                 <option value=37>37</option>
                 <option value=38>38</option>
                 <option value=39>39</option>

                 <option value=40>40</option>
                 <option value=41>41</option>
                 <option value=42>42</option>
                 <option value=43>43</option>
                 <option value=44>44</option>
                 <option value=45>45</option>
                 <option value=46>46</option>
                 <option value=47>47</option>
                 <option value=48>48</option>
                 <option value=49>49</option>

                 <option value=50>50</option>
                 <option value=51>51</option>
                 <option value=52>52</option>
                 <option value=53>53</option>
                 <option value=54>54</option>
                 <option value=55>55</option>
                 <option value=56>56</option>
                 <option value=57>57</option>
                 <option value=58>58</option>
                 <option value=59>59</option>

                 <option value=60>60</option>
                 <option value=61>61</option>
                 <option value=62>62</option>
                 <option value=63>63</option>
                 <option value=64>64</option>
                 <option value=65>65</option>
                 <option value=66>66</option>
                 <option value=67>67</option>
                 <option value=68>68</option>
                 <option value=69>69</option>

                 <option value=70>70</option>
                 <option value=71>71</option>
                 <option value=72>72</option>
                 <option value=73>73</option>
                 <option value=74>74</option>
                 <option value=75>75</option>
                 <option value=76>76</option>
                 <option value=77>77</option>
                 <option value=78>78</option>
                 <option value=79>79</option>

                 <option value=80>80</option>
                 <option value=81>81</option>
                 <option value=82>82</option>
                 <option value=83>83</option>
                 <option value=84>84</option>
                 <option value=85>85</option>
                 <option value=86>86</option>
                 <option value=87>87</option>
                 <option value=88>88</option>
                 <option value=89>89</option>

                 <option value=90>90</option>
                 <option value=91>91</option>
                 <option value=92>92</option>
                 <option value=93>93</option>
                 <option value=94>94</option>
                 <option value=95>95</option>
                 <option value=96>96</option>
                 <option value=97>97</option>
                 <option value=98>98</option>
                 <option value=99>99</option>
</select></td>
</tr>
</table>
<br><br>
<table border=0>

<tr><td valign=top>
<font face=calibri color=#009933><h3>1) From where did you hear about Angrybullet2 ?</h3></font>
<font face=calibri color=black><input type=radio name=hear-about value=Search engines (google, yahoo, bing)> Search engines (google, yahoo, bing, &#8230 )<br>
 <input type=radio name=hear-about value=From a friend> From a friend<br>
 <input type=radio name=hear-about value=From YouTube> From YouTube<br>
 <input type=radio name=hear-about value=Other:> Other</font>

<br><br>

<font face=calibri color=#009933><h3>2) Are you subscribed to Angrybullet2 ?</h3></font>
<font face=calibri color=black>
    <input type=radio name=sub-or-not value=Yes> Yes, I am<br>
    <input type=radio name=sub-or-not value=No, but I wish to subscribe> No, but I wish to subscribe<br>
    <input type=radio name=sub-or-not value=No, I am not, and I won't subscribe> No, I am not, and I won't subscribe<br>
    <input type=radio name=sub-or-not value=No account> I don't have a YouTube account</font>

<br><br>

<font face=calibri color=#009933><h3>3) How many videos of Angrybullet2 did you watch ?</h3></font>
<font face=calibri color=black><input type=radio name=n videos watched value=None> None<br>
                                     <input type=radio name=n-vids-watched value=1-2> 1-2<br>
                                     <input type=radio name=n-vids-watched value=3-4> 3-4<br>
                                     <input type=radio name=n-vids-watched value=5-9> 5-9<br>
                                     <input type=radio name=n-vids-watched value=10 and more> 10 and more</font>

<br><br>

<font face=calibri color=#009933><h3>4) Did you enjoy watching videos from Angrybullet2 ?</h3></font>
<font face=calibri color=black>
                     <input type=radio name=enjoy-or-not value=Yes, I did> Yes, I did<br>
                     <input type=radio name=enjoy-or-not value=No, I didn't> No, I didn't<br>
                     <input type=radio name=enjoy-or-not value=I watched none of your videos> I watched none of your videos</font>

<br><br>

<font face=calibri color=#009933><h3>5) What was the type of the video(s) you watched ?</h3></font>
<font face=calibri color=black>
                     <input type=checkbox name=vid-type value=Tutorial(s)> Tutorial(s) (how to)<br>
                     <input type=checkbox name=vid-type value=Sound effect(s)> Sound effect(s)<br>
                     <input type=checkbox name=vid-type value=Experiment(s)> Experiment(s)<br>
                     <input type=checkbox name=vid-type value=I watched none of your videos> I watched none of your videos</font>

<br><br>

<font face=calibri color=#009933><h3>6) Do you have any suggestion in order to make Angrybullet2 better ?</h3></font>
    <textarea rows="10" cols="75" name="suggestions"></textarea></td></tr></table>

<table border=0><tr><td valign=top>
<input type="submit" value="Submit survey" class=button></td><td><input type="reset" value="Reset survey fields" class=button></td></tr></table>
</td></tr></Table>
</form>
</div>
</html>

我的 PHP 脚本:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$hear about = $_POST['hear-about'];
$sub-or-not = $_POST['sub-or-not'];
$n-vids-watched = $_POST['n-vids-watched'];
$enjoy-or-not = $_POST['enjoy-or-not'];
$vid-type = $_POST['vid-type'];
$suggestions = $_POST['suggestions'];
$formcontent=" Name: $name \n Email: $email \n Gender: $gender \n Age: $age \n Hear-about: $hear-about \n Sub-or-not: $sub-or-not \n N-vids-watched: $n-vids-watched \n Enjoy-or-not: $enjoy-or-not \n Vid-type: $vid-type \n Suggestions: $suggestions";
$recipient = "angrybullet2@gmail.com";
$subject = "Survey response";
$mailheader = "From: $name \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!"<a href=http://google.com>go to google</a>;
?>
4

4 回答 4

1

变量名中不能有空格或破折号。

$hear about = $_POST['hear-about'];

应该

$hearabout = $_POST['hear-about'];

或者

$hear_about = $_POST['hear-about'];
于 2013-08-21T20:52:16.033 回答
1

语法高亮显示错误。变量名中不能有破折号。

$sub-or-not // bad
$n-vids-watched // bad
$enjoy-or-not // bad
$vid-type// bad

空格也一样:

$hear about // bad


$sub_or_not // good
$n_vids_watched // good
$enjoy_or_not // good
$vid_type // good
$hear_about // good
于 2013-08-21T20:51:23.360 回答
0
$sub-or-not // variables like these are not proper variables

请参考http://php.net/manual/en/language.variables.php

于 2013-08-21T20:52:42.393 回答
0

问题是您在代码中使用破折号。同样在第 6 行,变量中有一个空格,您也不能这样做。

将您的 PHP 代码更改为:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$hea_about = $_POST['hear-about'];
$sub_or_not = $_POST['sub-or-not'];
$n_vids_watched = $_POST['n-vids-watched'];
$enjoy_or_not = $_POST['enjoy-or-not'];
$vid_type = $_POST['vid-type'];`enter code here`
$suggestions = $_POST['suggestions'];
$formcontent=" Name: $name \n Email: $email \n Gender: $gender \n Age: $age \n Hear-about: $hear-about \n Sub-or-not: $sub-or-not \n N-vids-watched: $n-vids-watched \n Enjoy-or-not: $enjoy-or-not \n Vid-type: $vid-type \n Suggestions: $suggestions";
$recipient = "angrybullet2@gmail.com";
$subject = "Survey response";
$mailheader = "From: $name \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! </br> <a href=\"http://google.com\">Go to Google</a>";
?>
于 2013-08-21T20:59:43.023 回答