📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials CodeIgniter 4 Email in CI4

Email in CI4

4 min read
Send emails with CI4's Email service — configure SMTP, set recipients, HTML body, and attachments.

Sending Email

// app/Config/Email.php
public string $fromEmail    = "noreply@example.com";
public string $fromName     = "My App";
public string $protocol     = "smtp";
public string $SMTPHost     = "smtp.gmail.com";
public int    $SMTPPort     = 587;
public string $SMTPUser     = "you@gmail.com";
public string $SMTPPass     = "";  // use env variable
public string $SMTPCrypto   = "tls";

// Send email
$email = ConfigServices::email();

$email->setFrom("me@example.com", "MyApp");
$email->setTo("user@example.com");
$email->setCC("cc@example.com");
$email->setSubject("Welcome!");
$email->setMessage(view("emails/welcome", ["user" => $user]));
$email->setAltMessage("Plain text version");

if ($email->send()) {
    echo "Sent!";
} else {
    log_message("error", $email->printDebugger());
}