Send Email with mail() in PHP
Fire-and-forget mail via the built-in mail() — fine for low-volume.
Author:
chris
// Language: PHP
<?php
declare(strict_types=1);
$to = 'user@example.com';
$subject = 'Hello from PHP';
$body = "This is a test message.\n";
$headers = "From: noreply@example.com\r\n" .
"Content-Type: text/plain; charset=UTF-8\r\n";
if (!mail($to, $subject, $body, $headers)) {
fwrite(STDERR, "mail() failed\n");
exit(1);
}