我有相当基本的 HTML 和 CSS 知识,从头开始构建我的网站。我在 iFrame 中使用 JotForm 作为我的联系表单,但想将其更改为 PHP 表单,因此我不依赖这些人,并且我可以更好地控制表单的外观。
我最初确实让表单发送了一封带有空白字段的电子邮件 - 我试图解决这个问题,但现在已经完全搞砸了。
很感谢任何形式的帮助。
这是我在表格中列出的表单的 HTML;
<table width="400" border="0" align="left" cellpadding="5" id="form">
<tr>
<th width="134" scope="row" align="right">NAME</th>
<th width="240" scope="row">
<form name="name" method="post" action="contact.php">
<span id="sprytextfield1">
<input type="text" name="name" id="name" value="<?php print "$nameField"; ?>">
<span class="textfieldRequiredMsg">A value is required.</span><spanclass="textfieldInvalidFormatMsg">Invalid format.</span></span>
</form></th>
</tr>
<tr>
<th scope="row"> </th>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row" align="right">EMAIL</th>
<th scope="row">
<form name="email" method="post" action="contact.php">
<span id="sprytextfield2">
<input type="text" name="email" id="email" value="<?php print "$emailField"; ?>">
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
</form></th>
</tr>
<tr>
<th scope="row"> </th>
<th scope="row"> </th>
</tr>
<tr>
<th height="128" scope="row" align="right">MESSAGE</th>
<th scope="row">
<form name="message" method="post" action="contact.php">
<span id="sprytextarea1">
<textarea name="message" id="message" cols="45" rows="5"><?php print "$messageField"; ?></textarea>
<span class="textareaRequiredMsg"><br>
A value is required.</span></span>
</form></th>
</tr>
<tr>
<th scope="row"> </th>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
<th scope="row"><form name="submit" method="post" action="contact.php">
<input type="hidden" name="parse_var" id="parse_var" value="contactform">
<input type="submit" name="submit" id="submit" value="SEND MESSAGE">
</form></th>
</tr>
<tr>
<th scope="row"> </th>
<th scope="row"><?php print "$sent"; ?></th>
</tr>
</table>
和我的PHP:
<?php
if ($_POST['parse_var'] == "form") {
$emailTitle = 'New Contact Form Message';
$yourEmail = 'charlotte@charlottemay.co.uk';
$emailField = $_POST['email'];
$nameField = $_POST['name'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br />
Name: $nameField <br />
Message: $messageField <br />
EOD;
$headers = "From: $emailField\r\n";
$headers .= "content-type: text/html\r\n";
$success = mail("$yourEmail", "$emailTitle", "$body", "$headers");
$sent = "thankyou, your message has been successfully sent x";
}
?>