Thanks in advance dor any help.
My site is with hostinger and the front end is fine, however when the contact form is filled out and button pushed i get a Http 500 Error.
This is the PHP code, spoke with hostinger and changed the details for the server still the same. Any Ideas.
<?php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;
require "vendor/autoload.php";
if(isset($_POST["Submit"])){
$name = $_POST["fullname"];
$email = $_POST["email"];
$mobile = $_POST["phone"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$mail = new PHPMailer(true);
// $mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->SMTPSecure = 'ssl';
$mail->SMTPSecure = 'tls';
$mail->isHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "Arsenal@#2004";
$mail->setFrom($email, $name);
$mail->addAddress("[email protected]", "Envitics");
$mail->Subject = "Inquiry from SEOHunt";
$mail->Body = "Name : $name <br> Email : $email <br> Phone Number : $mobile <br> Subject : $subject <br> Message : $message";
$secret = "6LfYBfcpAAAAAEykcY3Q3FiJ2T5vVCM2y-kYxPZF";
// Empty response
$response = null;
// Check if the form was submitted
if ($_POST["g-recaptcha-response"]) {
$response = $_POST["g-recaptcha-response"];
}
// Verify the reCAPTCHA response
if ($response != null) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => $secret,
'response' => $response
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencodedrn",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$json = json_decode($result);
if ($json->success) {
$mail->send();
echo '<script>alert("Mail sent successfully."); window.location.href = "index.html";</script>';
} else {
// reCAPTCHA verification failed
echo '<script>alert("Error in Google reCAPTACHA"); window.location.href = "index.html";</script>';
}
} else {
echo '<script>alert("No response for reCAPTCHA"); window.location.href = "index.html";</script>';
}
}
Error Message.
atal error: Uncaught PHPMailerPHPMailerException: SMTP Error: Could not authenticate. in /home/u979039019/domains/seohunt.co.uk/public_html/vendor/phpmailer/phpmailer/src/PHPMailer.php:2265 Stack trace: #0 /home/u979039019/domains/seohunt.co.uk/public_html/vendor/phpmailer/phpmailer/src/PHPMailer.php(2062): PHPMailerPHPMailerPHPMailer->smtpConnect() #1 /home/u979039019/domains/seohunt.co.uk/public_html/vendor/phpmailer/phpmailer/src/PHPMailer.php(1689): PHPMailerPHPMailerPHPMailer->smtpSend() #2 /home/u979039019/domains/seohunt.co.uk/public_html/vendor/phpmailer/phpmailer/src/PHPMailer.php(1523): PHPMailerPHPMailerPHPMailer->postSend() #3 /home/u979039019/domains/seohunt.co.uk/public_html/form.php(70): PHPMailerPHPMailerPHPMailer->send() #4 {main} thrown in /home/u979039019/domains/seohunt.co.uk/public_html/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 2265