What is the Email library in CodeIgniter 4?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex CodeIgniter topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

CodeIgniter 4's Email class sends emails via SMTP, PHP's mail(), or Sendmail. Get the service: $email = \Config\Services::email(). Configure in app/Config/Email.php or at runtime. Usage: $email->setFrom("from@example.com", "My App")->setTo("to@example.com")->setSubject("Hello")->setMessage("<p>Body</p>")->setMailType("html")->send(). Attachments: $email->attach("/path/to/file.pdf"). CC and BCC: $email->setCC("cc@example.com"). For SMTP, configure $protocol = "smtp", $SMTPHost, $SMTPPort, $SMTPUser, $SMTPPass, and $SMTPCrypto = "tls". Debug email issues: $email->printDebugger(["headers", "subject", "body"]). Consider using a third-party service (Mailgun, SendGrid) with Guzzle for production reliability.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a CodeIgniter codebase.