Skip to content
PHP Logo

What are the best practices for adding additional headers, such as "From," when using the mail() function in PHP?

When using the mail() function in PHP to send emails, it is important to include additional headers such as "From" to ensure that the email is properly formatted and delivered. To add a "From" header, you can use the additional_headers parameter in the mail() function and specify the email address you want to use as the sender.

php
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";

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