I am getting an error when I try to send mail using the codeigniter email service(using CI version 4.5.3). I have used the same email configuration for successfully sending emails with previous versions of Codeigniter 4.
The error says: Unable to send email using SMTP. Your server might not be configured to send mail using this method.
My controller code is as follows:
class SendEmail extends BaseController {
public function index() {
$recipient = "[email protected]";
$subject = "Test Mail";
$message = "<p>Hi,This is a test mail.</p>";
$email = service('email');
$email->setFrom("[email protected]");
$email->setTo($recipient);
$email->setSubject($subject);
$email->setMessage($message);
if($email->send()) {
echo "Email sent successfully";
}
else {
$data = $email->printDebugger(['headers']);
print_r($data);
echo "Email sending failed";
}
}
}
My .env file :
#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------
CI_ENVIRONMENT = development
Can anyone please help with this?