我需要制作一个网络表单供用户输入他们的信息,从下拉菜单中选择一些选项,并包含一个附件。提交此表单时,它应该生成并向我发送电子邮件。
所有字段都有效(因为它们显示在我收到的电子邮件中)附件(我不知道如何使附件正常工作)。我只上过 HTML 课程的介绍,从未学习过 PHP,而且在没有完全重写所有代码的情况下,似乎再多的谷歌搜索也无法得到我想要的答案。我希望这是一个快速修复,我只是忽略了一些东西。
这是我的 HTML 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="container">
<header>
</header>
<div id="maincontent">
<script>
$(document).ready(function() {
$(':text:first').focus();
});
</script>
<div id="form_container">
<form action="sendemail.php" method="post" enctype="multipart/form-data">
<ul id="emailform">
<li>
<label for="ef_title">Title: </label>
<span class="fieldbox"><input type="text" name="ef_title" required="required"></span>
</li>
<li>
<label for="ef_users">Users Impacted: </label>
<span class="fieldbox"><input type="text" name="ef_users" required="required"></span>
</li>
<li>
<label for="ef_datetime">Date/Time: </label>
<span class="fieldbox"><input type="datetime" name="ef_datetime" required="required"></span>
</li>
<li>
<label for="ef_priority">Priority: </label>
<p>
<select name="selectpri" required="required">
<option value="">Select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</p>
<!-- <span class="fieldbox"><input type="datetime" name="ef_datetime" required="required"></span> -->
</li>
<li>
<label for="ef_blocking">Blocking: </label>
<p>
<select name="selectblock" required="required">
<option value="">Select...</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</p>
</li>
<li>
<label for="ef_url">URL of Observed Behavior: </label>
<span class="fieldbox"><input type="url" name="ef_url" required="required"></span>
</li>
<li>
<label for="ef_desc">Description of Behavior: </label>
<span class="msgbox"><textarea class="area" name="ef_desc" required="required"></textarea></span>
</li>
<li>
<label for="ef_results">Expected Results: </label>
<span class="msgbox"><textarea class="area" name="ef_results" required="required"></textarea></span>
</li>
<li>
<label for="ef_repro">Repro Steps: </label>
<span class="msgbox"><textarea class="area" name="ef_repro" required="required"></textarea></span>
</li>
<li>
<label for='uploaded_file'>Select A File To Upload:</label>
<input type="file" name="file" id="file">
</li>
</ul>
<input id="sendbutton" type="submit" value="Send">
<input id="clearbutton" type="reset" value="Clear">
<br /><br />
</form>
</div>
</div>
<footer>
</footer>
</div>
</body>
</html>
这是我的 PHP 代码:
<?php
$field_title = $_POST['ef_title'];
$field_users = $_POST['ef_users'];
$field_datetime = $_POST['ef_datetime'];
$field_priority = $_POST['selectpri'];
$field_blocking = $_POST['selectblock'];
$field_url = $_POST['ef_url'];
$field_desc= $_POST['ef_desc'];
$field_results = $_POST['ef_results'];
$field_repro = $_POST['ef_repro'];
$field_attach = $_POST['file'];
$mail_to = 'katcole@uw.edu';
$subject = $field_title;
$body_message .= 'Title: '.$field_title."\n";
$body_message .= 'Users: '.$field_users."\n";
$body_message .= 'Date/Time: '.$field_datetime."\n";
$body_message .= 'Priority: '.$field_priority."\n";
$body_message .= 'Blocking: '.$field_blocking."\n";
$body_message .= 'URL of Observed Behavior: '.$field_url."\n";
$body_message .= 'Description of Behavior: '.$field_desc."\n";
$body_message .= 'Expected Results: '.$field_results."\n";
$body_message .= 'Repro Steps: '.$field_repro."\n";
$body_message .= 'Attachments: '.$field_attach."\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to v-jacoca@microsoft.com');
window.location = 'index.html';
</script>
<?php
}
?>
感谢您在这件事上的帮助!:)