So this exact code has worked to send emails before. I've uploaded it into the same directory it was previously in.
I'm not being given a any PHP code errors, nor is anything being added to the error_log so it leads me to believe that it must be a server issue and that I may be missing something with the code. To me though, it looks fine, has no errors and hasn't changed since the last time it was on the server.
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit']))
{
// Values need to be santiised
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$date = $_POST['date'];
$time = $_POST['time'];
$timestamp =date('l jS \of F Y h:i:s A');
$text = "".$forename.",".$surname.",".$email.",".$phone.",".$service.",".$date.",".$time.",".$timestamp." \n";
$file = fopen("./data/requests.csv","a+ \n");
fwrite($file, $text);
fclose($file);
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply@handler.net';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->setFrom('noreply@handler.net','Bookings | Email'); // Emails sent via noreply.
$mail->addAddress('bookings@salon.com','Bookings'); // Email form responses sent to bookings@salon.com
$mail->addReplyTo($email,$forename.' '.$surname); // Reply to the user who submitted the form.
$mail->addBCC('outbox@handler.net',''); // Store record of all emails sent via the system in outbox@handler.net
$mail->Subject = 'Booking Request from '.$forename.' '.$surname.' '; // Subject of the email sent to bookings@salon.com that the form responses will be contained within.
$mail->isHTML(TRUE);
$mail->Body = <<<EOD
<!-- Email contents goes here -->
EOD;
if(!$mail->send()) { // Send the email.
echo '';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo '';
}
}
?>
I'm not too sure what else to try now as this was working. If there are any code errors I'd appreciate some comments or guidance as I've had it working already and can't figure out what the issue is other than it being server side.
Any help would be appreciated.