Code Snippets

<?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);
}