我的联系表格在测试/PHPMailer后给了我一个内部服务器错误(500)
My contact form gives me an internal server error (500) after testing / PHPMailer
我以前做过自己的mail.php,但我一直在学习PHPMailer,并希望在我的表单上为我正在开发的新网站实现它。每次我通过输入信息并点击发送来测试它时,它都会给我一个内部服务器错误,并没有真正解释原因,但它可能与我的头有关。
我的网站/页面供参考
我的代码:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="php/mail.php" method="POST">
<div class="form-group">
<input type="text" class="form-control" id="name" placeholder="Full Name" required>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Email Address" required>
<small class="text-muted">I will never share your email with anyone. Pinky swear.</small>
</div>
<div class="form-group">
<input type="phone" class="form-control" id="phone" placeholder="Phone Number" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="company" placeholder="Company (optional)">
</div>
<div class="form-group">
<div class="radio">
<label>
<input type="radio" name="radio" id="optionsRadios1" value="Project" checked>Project
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio" id="optionsRadios2" value="Collab">Collaboration
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="radio" id="optionsRadios3" value="Other">Other
</label>
</div>
</div>
<div class="form-group">
<textarea class="form-control" id="message" rows="4" placeholder="What do you need?" required></textarea>
</div>
<button class="btn btn-primary" style="float: right;" type="submit">Send Away!</button>
</form>
这是我的php
<?php
//gather all form fields
$name = mysqli_real_escape_string($db, $_POST['name']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$phone = mysqli_real_escape_string($db, $_POST['phone']);
$company = mysqli_real_escape_string($db, $_POST['company']);
$radio = mysqli_real_escape_string($db, $_POST['radio']);
$message = mysqli_real_escape_string($db, $_POST['message']);
if($name == "" || $email == "" || $phone == "" || $company == "" || $radio == "" || $message == "" ){
//this could load a modal or some type of error pop up
echo '<div class="alert alert-danger">The form submission is missing values.</div>';
exit();
}
else {
//include autoload
require 'php/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isMail(); // Set mailer to use SMTP
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('renegade13design@gmail.com', 'Joe User'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = '
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="" type="text/css" media="screen, projection" />
<style>
h1 { font-size: 14px; }
body {font-family: helvetica neue, arial;}
</style>
</head>
<body>
<table style="width: 600px; padding: 12px;" align="center">
<tr>
<td><img src="img/form.jpg"></td>
</tr>
<tr>
<td><strong>Full Name:</strong> '.$name.'</td>
</tr>
<tr>
<td><strong>Email Address:</strong> '.$email.'</td>
</tr>
<tr>
<td><strong>Phone Number:</strong> '.$phone.'</td>
</tr>
<tr>
<td><strong>Company:</strong> '.$company.'</td>
</tr>
<tr>
<td><strong>What do you want?:</strong> '.$radio.'</td>
</tr>
<tr>
<td><strong>What do you need?:</strong> '.$message.'</td>
</tr>
</table>
</body>
</html>
';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
header( 'http://www.scratchmediaohio.com/twentysixteen' );
}
}
?>
您的某些输入没有"name"属性,因此它们不会是$_POST数组的一部分,因此不会出现在您的邮件脚本中。
<input type="text" class="form-control" id="name" placeholder="Full Name" required>
应该是
<input type="text" class="form-control" name="name" id="name" placeholder="Full Name" required>
对于您的输入:姓名、电子邮件、电话和公司-唯一有它们的是收音机选择。我还建议对您的输入进行比目前更多的验证。
相关文章:
- 如何从另一个处理程序内部取消JavaScript事件处理程序函数的执行
- 相对于他在jQuery/Js中的一个内部数据对数组进行排序
- 我的联系表格在测试/PHPMailer后给了我一个内部服务器错误(500)
- 将每个函数与 getJSON 一起使用一个内部文件
- Redux 操作创建者在另一个内部调用一个
- 在打字稿中隐式引用另一个内部模块
- 在 PHP 中将一个外部图像替换为另一个内部图像
- 我想打开点击两个页面,一个内部页面和一个外部页面
- 如何创建一个内部带有延迟/超时的 javascript 书签
- JavaScript可以't调用另一个内部的原型函数
- 为JavaScript正则表达式找到一个内部模式倍数的优雅的单个正则表达式
- 如何定义一个(内部)任务,而不把它列在“grunt——help”中
- 这个函数如何将实参传递给另一个内部函数形参
- 一次向一个元素添加两个元素,一个在另一个内部
- 在React性能度量代码中有一个内部错误
- 为什么在另一个内部调用的函数不能访问外部函数的作用域?
- 当链接被点击时改变一个内部锚标记css
- Casperjs测试一个内部站点
- 返回一个内部带有回调函数的函数
- 如何获得一个内部对象文字值与javascript