When we send mail from portal I got error message :- Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.

Minal Deogirikar 0 Reputation points
2023-10-11T09:55:31.6033333+00:00
public function process($value='')
	{
		require (APPPATH."libraries/vendor/autoload.php"); 
   		 $mail = new PHPMailer(true);                      
        try {           
            $mail->SMTPDebug = 0;                                       
            $mail->isSMTP();                                            
            $mail->Host       = 'smtp.example.com';                     
            $mail->SMTPAuth   = true;                             
            $mail->Username   = '******@example.in';                 
            $mail->Password   = 'example@123';                        
            $mail->SMTPSecure = 'STARTTLS';                              
            $mail->Port       = 587;  
            
            $from ='******@ck.in';
            $to='******@ck.in';
            $cc='******@gmail.com';

            $mail->setFrom($from, 'CT Account Dept');
            $mail->addAddress($to);
            $mail->addCC($cc);
            $mail->isHTML(true);                                  
            $mail->Subject = "testing email";
            $mail->Body    = "Thanks for contacting regarding xyz.";
        
			if($mail->send())
			{	
				 $msg = array('status' =>200 , 'msg'=>'Send Invoice successfully.'); 
			}
			else
			{
				$msg = array('status' =>307 , 'msg'=>'Send Invoice failed.'); 
			}
			put_msg($msg);
			

		} 
        catch (Exception $e) 
        {
            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }
	}

above code is Using php codigniter, mail cannot be send. please help me to solve this problem.
Developer technologies | .NET | Other
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.