I have a contact form that uses php. Intermittently it fails with the error:
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@website.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Setting SMTPDebug to 3 shows no information prior to the failure.
Looking at the log files I see:
Premature end of script headers
Connection reset by peer: mod_fcgid: error reading data from FastCGI
PHP version is currently 5.6, although I changed to 7.0 and it made no difference. I switched from FastCGI to CGI and that also made no difference.
The php form looks like this:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require '/home/username/phpmailer/vendor/autoload.php';
if(isset($_POST['submit']))
{
$message=
'Full Name: '.$_POST['fullname'].'<br />
Email: '.$_POST['emailid'].'<br />
Comments: '.$_POST['comments'].'
';
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Host = "smtp-mail.outlook.com"; //Gmail SMTP server address
$mail->Port = 587; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "myusername@outlook.com"; // Your full Gmail address
$mail->Password = "mypassword"; // Your Gmail password
// Compose
$mail->setFrom('myusername@outlook.com', 'Mailer');
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress("myusername@outlook.com", "My Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? '<div class="alert alert-success" role="alert"><strong>Thank you for contacting me.</strong></div>' : '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem delivering the message.</div>';
unset($mail);
}
?>
When it fails, it will probably (not always) work on the next try immediately afterwards. I can see no pattern to the failures.
I have read comments about mod_security being the cause or editing .htaccess, but I'm in unchartered waters. I don't want to do something that causes a security hole.
I'd appreciate any help.