You don’t need to set Date and Message-ID as they are set by your mail server automatically.
The web hosting service does not set it automatically and requires them to be set.
If I run their example, below, I can send mail to external gmail, but not via wordpress and cf7
<?php
// Data för mailet
$sender = "noreply@mywordpressdomain.se";
$sendername = "My page";
$recipient = "mygmailadress@gmail.com";
$recipientname = "My name";
$subject = "Subject for the mail";
$message = "mail content";
// Generera datum och mailets id
$date = date(DATE_RFC2822);
$mid = "<" . sha1(microtime()) . "@" . $_SERVER['HTTP_HOST'] . ">";
// Ställ in rätt kodningstyp
mb_internal_encoding("UTF-8");
// Rätt kodning för avsändare och mottagares namn
$sendername = mb_encode_mimeheader($sendername);
$recipientname = mb_encode_mimeheader($recipientname);
// Sätt headers
$headers =<<<EOT
From: $sendername <$sender>
Date: $date
Message-ID: $mid
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
EOT;
// Skicka mail
$status = mb_send_mail("$recipientname <$recipient>", $subject, $message, $headers, "-f$sender");
if(!$status) {
echo "Mail kunde inte skickas.";
}
else {
echo "Mail skickat!";
}
?>
If I add them to classes.php line 728
$additionaldate = date(DATE_RFC2822);
$additionalmid = "<" . sha1(microtime()) . "@" . $_SERVER['HTTP_HOST'] . ">";
$headers .= "Date: ". $additionaldate ."\n";
$headers .= "Message-ID: ". $additionalmid . "\n";
it works, but is there a way to set them directly in Additional Header-area instead? (so that the will not be overwritten when upgrading the plugin?
They shouldn’t be set manually. Even when the MTA doesn’t set them, PHPMailer does. If you are using any mail-related plugin that avoid PHPMailer, try deactivating it.
There seems to be a conflict in the way the date header is set between wordpress/wp-settings.php#L43
// WordPress calculates offsets from UTC.
date_default_timezone_set( 'UTC' );
and wp-includes/class-phpmailer.php#L2671
public static function rfcDate()
{
//Set the time zone to whatever the default is to avoid 500 errors
//Will default to UTC if it's not set properly in php.ini
date_default_timezone_set(@date_default_timezone_get());
return date('D, j M Y H:i:s O');
}
(I had date set to JST on server and in WP and php.ini, but still got UTC).
You can get around this by changing the line in wp-settings.php to your preferred timezone as per http://project-syatiku.com/archives/191.html
Possibly related:
https://core.trac.wordpress.org/ticket/11665
https://core.trac.wordpress.org/ticket/11672
HTH
PS Changing date_default_timezone_set() breaks CF7’s _date and _time variables. Sigh.