Skip to content

Getting SMTP Connection failed

Ashvinee12 edited this page Jun 1, 2024 · 1 revision

Hello,

require 'MailerVendor/autoload.php';

if($this->EmailType=='S') { //Send SMTP Email //--------------------------------------- $mailer = new PHPMailer; $mailer->IsSMTP(); $mailer->Host = $this->SMTPHost; $mailer->Port = 465; //$this->SMTPPort; $mailer->SMTPSecure = 'tls'; $mailer->SMTPAuth = TRUE; $mailer->Username =$this->SMTPUserName; $mailer->Password =$this->SMTPPassword; $mailer->setFrom($this->SMTPFromEmail, $this->SMTPFromName); $mailer->AddAddress($to); $mailer->IsHTML(true); $mailer->Body = $emailContent; $mailer->Subject = $subject; if($attatchementPath !=""){$mailer->addAttachment($attatchementPath);} $isEmailSend = $mailer->send();

if(!$mailer->send()) {
	echo 'Message could not be sent.';
	echo 'Mailer Error: ' . $mailer->ErrorInfo;
} else {
	echo 'Message has been sent';
}

unset($mailer);
//----------------------------------------------------  

}

I am using this code for send an email. But I am getting below error please give me solution on this.

Mailer Error: SMTP connect() failed.

image