Hi Team
I need some clarity on the way i am sending my email, i am using phpmailer. this is without composer. tried to use with composer i was still getting this same error. How has a knowldge of where could it the problem? Does this mean smtp settings are incorrect?
sender = "[email protected]";
$this->password = "***";
$this->smtpHost = "smtp-mail.outlook.com";
$this->smtpPort = 587;
}
// function to send email().
public function sendMail(){
$mail= new PHPMailer();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPDebug = 3;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPOptions = array(
'ssl'=> array(
'verify_peer'=>false,
'verify_peer_name' => false,
'allow_self_signed'=> true
)
);
$mail->Host = $this->smtpHost;
$mail->Port =$this->smtpPort;
$mail->IsHTML(true);
$mail->Username =$this->sender;
$mail->Password= $this->password;
$mail->Body=$this->getHTMLMessage();
$mail->Subject = "Your verification code is {$this->code}";
$mail->SetFrom($this->sender, "Verification Code");
$mail->AddAddress($this->receiver);
if($mail->send()) {
echo "Mail Sent Successfully";
exit;
}
echo "Failed to Send Mail";
}
// function to get html message from the email.
public function getHTMLMessage() {
$this->code=$this->getVerificationCode();
$htmlMessage=<<
Your verification code is {$this->code}
Use this code to verify your account.
MSG;
return $htmlMessage;
}
// get verificationCode.
public function getVerificationCode() {
return (int) substr(number_format(time() * rand(), 0, '', ''), 0, 6);
}
}
// instantiate VerificationCode and send email
$vc=new VerificationCode('[email protected]');
$vc->sendMail();
?>
Mohamed Azarudeen ZPosted May 9, 2023, 4:11 PM
Based on the code there are few things to check, kindly go through these once.
In addition you may want to set the
$mail->SMTPDebugproperty to a lower value (e.g. 2 or 1) to reduce the amount of debug output generated by PHPMailer. This may make it easier to identify the source of the problem.If you continue to experience issues, it may be helpful to review the PHPMailer documentation and examples to ensure that you are using the library correctly.