Good afternoon, I am trying to set up sending mail from the server using PHPMailer.
If I use the data to set up sending mail that Hostia offers me in the “Mail->accounts” section, I get the following error “Mailer Error: SMTP connect() failed”. But if I write in SMTP->host vltr.domain.com I get the error “smtp error: could not authenticate”. I don’t understand a bit what I need to do to make it work. Because I’m strictly following the instructions, but in the end it still doesn’t work.
This is my test code
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'vendor/autoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 4;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->Host = 'mail.domain.com';
$mail->Port = 587;//also tried 465 and 25
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = '[email protected]';
$mail->Password = 'pass';
$mail->setFrom('[email protected]', 'First Last');
$mail->addReplyTo('[email protected]', 'First Last');
$mail->addAddress('[email protected]', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
$mail->Body = 'Hello, this is my message.';
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}