I'm hosting a website from 000webhost.com and when I try to test my contact form, i get this error from the line $errors = [];
. I really need your help badly!
session_start();
require_once '../../lib/mailer/PHPMailerAutoload.php';
$errors = [];
if(isset($_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['contactno'], $_POST['message'])){
$fields = [
'fname'=>$_POST['fname'],
'lname'=>$_POST['lname'],
'email'=>$_POST['email'],
'contactno'=> $_POST['contactno'],
'message'=> $_POST['message']
];
foreach($fields as $field => $data){
if (empty($data)){
$errors[]='The ' . $field . ' field is required.';
}
}
if(empty($errors)){
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->Host = 'smtp.gmail.com';
$m->Username = 'icyraud@gmail.com';
$m->Password = 'giantboq1';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->isHTML();
$m->Subject = 'Contact Form Submitted';
$m->Body = 'From: ' . $fields['fname'] .' '. $fields['lname']. ' (' . $fields['email'] . ')<p>' . $fields['message'] . '</p>';
$m->FromName = 'Contact';
$m->AddAddress('icyraud@gmail.com','JDGS Company');
if($m->send()){
header('Location: thanks.php');
die();
} else{
$errors[]= 'Sorry, could not send email. Try again later.';
}
}
} else{
$errors[] = 'Something went wrong';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('Location: contact-us.php');