Skip to content
PHP Logo

What are the correct mail headers to use in PHP to prevent emails from being marked as spam by GMX & Co.?

To prevent emails from being marked as spam by GMX & Co., it is important to set proper headers in the email sent via PHP. This includes setting the "From" header to a valid email address from the sending domain, adding a "Reply-To" header, and ensuring that the email content is not flagged as spammy by including relevant content. Additionally, using proper authentication methods such as SPF and DKIM can also help improve email deliverability.

php
// Set proper headers to prevent emails from being marked as spam
$to = "recipient@example.com";
$subject = "Important Email";
$message = "This is a test email.";

$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

// Send the email
mail($to, $subject, $message, $headers);