我一直在尝试设置一个简单的表单,使用phpmailer向用户发送电子邮件。当我提交表单时,我收到一条错误,上面写着"无法POST /public/mail_handler.php"。我不知道这是从哪里来的。这是html:
<title> Schedule an Appointment - Name </title>
<link rel="stylesheet" type="text/css" href="public/styles.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="public/script.js"></script>
<ul id="nav">
<li><a href="page.html"> Home </a><br>
<br>
<li><a class="active" href=""> Appointment </a> <br>
<br>
<li><a href="specsPage.html"> Build </a> <br>
<br>
<li><a href="contactPage.html"> Contact </a> <br>
<br>
</ul>
<div id="schedulePage">
<h4> Schedule an Appointment </h4>
<div id="fullForm">
<form id="appt" action="public/mail_handler.php" method="POST">
First Name: <input type="text" name="firstname" placeholder="First Name..."> <br>
<br>
Last Name: <input type="text" name="lastname" placeholder="Last Name..."> <br>
<br>
Email: <input type="text" name="email" placeholder="Email..."> <br>
<br>
Phone Number: <input type="text" name="phone" placeholder="Callback Number..."> <br>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
和php代码:
<?php
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
require("public/phpmailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost:4000";
$mail->SMTPAuth = true;
$mail->Username = "send_from_PHPMailer@name"; // hidden
$mail->Password = "pass"; // hidden
$mail->From = $email;
$mail->AddAddress("test@gmail.com", "Test Account");
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = "Your appointment details.";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>