Sending emails with PHP's mail() function

Tips on using PHP's mail() function

Updated on 08/11/2022

PHP's mail() function is enabled by default on our web hosting, so you can send emails with your PHP scripts.

By default, no sender is filled in when you use PHP's mail() function, so it is necessary to define it in your script using the additional headers:

<?php
$to      = 'recipient@example.com';
$subject = 'Message subject';
$message = 'Message content';
$headers = 'From: sender@example.com';

mail($to, $subject, $message, $headers);
?>

For more details on the use of additional headers for the mail() function, see the official PHP website.