通过PHP向邮件提交表单详细信息
我对PHP相当陌生。所以,这可能是我犯的一个非常愚蠢的错误。我必须将表格的详细信息发送到mail id。我通过互联网浏览,得到了各种链接。我得到了文件,并根据需要进行了更改。但我面临着错误500,我无法理解这背后的原因 我的HTML是-通过PHP向邮件提交表单详细信息,php,jquery,html,ajax,forms,Php,Jquery,Html,Ajax,Forms,我对PHP相当陌生。所以,这可能是我犯的一个非常愚蠢的错误。我必须将表格的详细信息发送到mail id。我通过互联网浏览,得到了各种链接。我得到了文件,并根据需要进行了更改。但我面临着错误500,我无法理解这背后的原因 我的HTML是- <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <!-- Always force la
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>app</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div id="form-messages" class="success">
</div>
<form id="ajax-contact" method="post" action="mailer.php">
<div class="field">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="field">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="field">
<label for="message">Message:</label>
<textarea id="message" name="message" required> </textarea>
</div>
<div class="field">
<button type="submit">Send</button>
</div>
</form>
</body>
</html>
谁能调查一下这个问题吗。我没有太多,我无法解决这个问题。请帮助我?因为您有代码,所以它给出了500个错误
http_response_code(500);
在else条件下,被调用的可能是因为phpmail()
功能在localhost(或您正在使用的服务器)上不可用
或者,您可以使用任何SMTP类来发送电子邮件。此外,您还可以使用SMTP类配置您的gmail id。可能是因为您没有设置邮件凭据。请参见此处的“如何执行此操作”。
您是否在php.ini文件中配置了邮件凭据?或者你应该使用swift邮件发送功能,这是一个简单的邮件发送功能。是的,我配置了邮件id]
$(function() {
// Get the form.
var form = $('#ajax-contact');
// Get the messages div.
var formMessages = $('#form-messages');
// Set up an event listener for the contact form.
$(form).submit(function(e) {
// Stop the browser from submitting the form.
e.preventDefault();
// Serialize the form data.
var formData = $(form).serialize();
// Submit the form using AJAX.
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
}).done(function(response) {
// Make sure that the formMessages div has the 'success' class.
$(formMessages).removeClass('error');
$(formMessages).addClass('success');
// Set the message text.
$(formMessages).text(response);
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#message').val('');
}).fail(function(data) {
// Make sure that the formMessages div has the 'error' class.
$(formMessages).removeClass('success');
$(formMessages).addClass('error');
// Set the message text.
if (data.responseText !== '') {
$(formMessages).text(data.responseText);
} else {
$(formMessages).text('Oops! An error occured and your message could not be sent.');
}
});
});
});
http_response_code(500);