I'm a game developer so I do not have any PHP/network/back end web development knowledge. I've been stuck with this problem all week with no luck online. Before PHPMailer, I tried using the mail() function in PHP but I was getting confused with all the .ini files. I found PHPMailer on this site in one of the answers and I have gotten much further. I followed this tutorial https://www.youtube.com/watch?v=FtWD_ZH9lnE&authuser=0 exactly, but the email will not send and debug is not printing out anything. My code always returns false and displays my "can't send email" message.
<?php session_start();
require_once 'PHPMailer/PHPMailerAutoLoad.php';
require_once 'PHPMailer/class.phpmailer.php';
$errors=[];
if(isset($_POST['name'], $_POST['twitterHandle'], $_POST['email'], $_POST['description'])) {
$fields = [
'name' => $_POST['name'],
'twitterHandle' => $_POST['twitterHandle'],
'email' => $_POST['email'],
'description' => $_POST['description']
];
foreach($fields as $field => $data){
if(empty($data)){
$errors[] = 'The ' . $field . ' field is required';
}
}
//mail connection if all fields are ! empty
if(empty($errors)){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = 1;
$mail->Host = 'smtp.gmail.com';
$mail->Username = '@gmail.com';
$mail->Password = 'pass';
$mail->SMTPSecure = 'ssl';
$mail->Port = 25;
$mail->isHTML;
$mail->Subject = 'subject';
$mail->Body = 'From: ' . $fields['name'] . ' (' . $fields['email'] . ')<p>' . $fields['description'] . '</p>';
$mail->FromName = 'Contact';
$mail->addReplyTo($fields['email'], $fields['name']);
$mail->addAddress('@gmail.com', 'name');
//send email
if($mail->send()){
header('Location: index.php');
die();
}else{
//cannot send
$errors[] = "Sorry, but I could not process your submission. Please try again.";
}
}
} else{
$errors[] = 'Something went wrong';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('Location: index.php');
?>
I have tried SSL on port 465 and 25 and also TLS on 587. I forwarded 465 and 25 on my network but 587 wont open. IMAP is also enabled on my gmail.