Javascript AngularJS-php邮件程序不断返回“500(内部服务器错误)”
处理联系人表单的app.js控制器如下所示:Javascript AngularJS-php邮件程序不断返回“500(内部服务器错误)”,javascript,php,angularjs,phpmailer,Javascript,Php,Angularjs,Phpmailer,处理联系人表单的app.js控制器如下所示: app.controller('ContactController', function ($scope, $http) { $scope.result = 'hidden' $scope.resultMessage; $scope.formData; //formData is an object holding the name, email, subject, and message $scope.submitButtonDisabled =
app.controller('ContactController', function ($scope, $http) {
$scope.result = 'hidden'
$scope.resultMessage;
$scope.formData; //formData is an object holding the name, email, subject, and message
$scope.submitButtonDisabled = false;
$scope.submitted = false; //used so that form errors are shown only after the form has been submitted
$scope.submit = function(contactform) {
$scope.submitted = true;
$scope.submitButtonDisabled = true;
if (contactform.$valid) {
$http({
method : 'POST',
url : 'contact-form.php',
data : $.param($scope.formData), //param method from jQuery
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } //set the headers so angular passing info as form data (not request payload)
}).success(function(data){
console.log(data);
if (data.success) { //success comes from the return json object
$scope.submitButtonDisabled = true;
$scope.resultMessage = data.message;
$scope.result='bg-success';
} else {
$scope.submitButtonDisabled = false;
$scope.resultMessage = data.message;
$scope.result='bg-danger';
}
});
} else {
$scope.submitButtonDisabled = false;
$scope.resultMessage = 'Failed :( Please fill out all the fields.';
$scope.result='bg-danger';
}
}
});
不幸的是,它不断返回500内部服务器错误。似乎找不到contact-form.php文件。我想它的路径无法被正确检测到。我仔细检查了一下,contact-form.php在主目录中,所以我猜它是有角度路径的
但问题可能在别处。也许粘贴contact-form.php代码也是值得的
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once 'phpmailer/PHPMailerAutoload.php';
if (isset($_POST['inputName']) && isset($_POST['inputEmail']) && isset($_POST['inputSubject']) && isset($_POST['inputMessage'])) {
//check if any of the inputs are empty
if (empty($_POST['inputName']) || empty($_POST['inputEmail']) || empty($_POST['inputSubject']) || empty($_POST['inputMessage'])) {
$data = array('success' => false, 'message' => 'Please fill out the form completely.');
echo json_encode($data);
exit;
}
//create an instance of PHPMailer
$mail = new PHPMailer();
$mail->From = $_POST['inputEmail'];
$mail->FromName = $_POST['inputName'];
$mail->AddAddress('test@gmail.com'); //recipient
$mail->Subject = $_POST['inputSubject'];
$mail->Body = "Name: " . $_POST['inputName'] . "\r\n\r\nMessage: " . stripslashes($_POST['inputMessage']);
if (isset($_POST['ref'])) {
$mail->Body .= "\r\n\r\nRef: " . $_POST['ref'];
}
if(!$mail->send()) {
$data = array('success' => false, 'message' => 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo);
echo json_encode($data);
exit;
}
$data = array('success' => true, 'message' => 'Thanks! We have received your message.');
echo json_encode($data);
} else {
$data = array('success' => false, 'message' => 'Please fill out the form completely.');
echo json_encode($data);
}
提前谢谢 错误500是一个服务器错误,请在php.ini中或通过ini_设置'display_errors','on',检查php服务器的logsTurn php Error on;在你的代码中。我应该在哪里粘贴这一行?在上面,你能访问ini文件吗?说实话,我没有看到任何ini文件。那么粘贴到contact-form.php中?