0

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?

4
  • Are you using sendmail or google smtp or other service? Commented Jul 9 at 5:18
  • I tried smtp with host: smtp-mail.outlook.com
    – DXB-DEV
    Commented Jul 9 at 8:04
  • 1
    Where is your username, password, port, protocol etc configuration? codeigniter.com/user_guide/libraries/… Commented Jul 9 at 8:46
  • To add to this, please post the whole email error message. Commented Jul 11 at 12:00

0

Browse other questions tagged or ask your own question.