You have a lot of comments in there, and I don't feel like digging through to figure out what's different between what you have and what I have. But here is my mailer code, it uses gmail and seems to work reliably.
private function initMailer()
{
$this->oMailer = new PHPMailer;
$this->oMailer->isSMTP();
$this->oMailer->SMTPDebug = 0;
$this->oMailer->Host = 'smtp.gmail.com';
$this->oMailer->Port = 587;
$this->oMailer->SMTPSecure = 'tls';
$this->oMailer->SMTPAuth = true;
$this->oMailer->Username = Config::GetValue('email', 'user');
$this->oMailer->Password = Config::GetValue('email', 'password');
$this->oMailer->setFrom(Config::GetValue('email', 'from'), Config::GetValue('email','from_name'));
$rt = Config::GetValue('email', 'reply_to');
if( isset($rt) )
{
$this->oMailer->addReplyTo($rt);
}
}
// Somewhere else in the class I use it:
$this->initMailer();
$this->oMailer->addAddress($oUser->email);
$this->oMailer->Subject = 'Welcome new user!';
$this->oMailer->msgHTML(
TemplateEngine::LoadView(
'user/email_welcome_user',
[
'username' => $oUser->username,
'site_url' => Config::GetValue('website', 'site_url')
]
)
);
$this->oMailer->AltBody = 'Thanks for signing up to derokorian.com';
if( !$this->oMailer->send() )
{
error_log('Failed sending welcome mail: ' . $this->oMailer->ErrorInfo);
}
Don't worry about the templateEngine or Config stuff, that's just my application's way of keeping everything from being inline. I'm not sure what you can drop from this, but this is what I set up to get it working every time. Try to compare it to your code, and maybe you'll see something different or missing? If you can't figure it out, I will try to look at it in detail this weekend while I'm traveling (aka while I sit at the gate at the airport).