what's the issue with Message-Id in email sent by php
Asked Answered
P

6

20

I have suspicious message-id header of email sent by php to gmail account:

Message-Id: <[email protected]>

Could you please tell does it have this strange format and what SMTPIN_ADDED_MISSING means here? Examples I saw in the internet had format something like this containing sending domain but my message id doesn't contain it for some reason:

[email protected]

I don't think I set this header in Zend_Mail. What generates this headers? Do you see any issues with this header?

Putandtake answered 23/1, 2013 at 16:0 Comment(0)
J
25

A proper outbound email client should be generating the Message-ID header when the email is sent. Google is being 'nice' and generating it for you when the message passes through its email system, but most won't, and most spam filters will take this missing header as an indication that the message is more likely to be spam. Any malformed or missing headers will add to the "spam score".

It is not difficult to generate, all that is required is that it is unique per-message:

$message-id = time() .'-' . md5($sender . $recipient) . '@' $_SERVER['SERVER_NAME'];

Or

$message-id = time() .'-' . md5($sender . $recipient) . '@yourdomain.com';

Gives:

[email protected]
Joellyn answered 23/1, 2013 at 17:19 Comment(9)
Do you mean that absense of Message_Id increases chances of going to spam?Putandtake
Could message_id contain domain of smpt server that sends email?Putandtake
Doesn't smpt server add message_id automatically, it should be added form the application, right?Putandtake
Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.Joellyn
Is it possible to configure SMTP server to add message id automatically not to send it in application?Putandtake
The <brokets> are part of the syntax, you need to have them around the identifier.Chancellor
@Chancellor thanks a lot! You saved me a lot of time! I believe you can make your comment an answer!Gladsome
If you are copy/pasting... don't forget the . between the '@' and $_SERVER['SERVER_NAME'];Phytohormone
This is a must have!Powell
A
8

Google SMTP generates it if missing. This header must be set by the first SMTP server. So you do not generate it - google does. It is used to prevent multiple delivery and to link related messages together.

It is not required to set message id header, but it's like a good practice for most (but not all, only configured) smtp to add (may be fix) this header. So to avoid generation of this header by others you can generate it by yourself.

Autorotation answered 23/1, 2013 at 16:53 Comment(6)
Should I set it from php or should server smpt server add them? Should message_id contain domain of server that sends address something like this: [email protected]?Putandtake
Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?Putandtake
SMTP server generates it when it does not exists. It's not necessery to generate from PHP. It muse include @domain part. Recommendations jwz.org/doc/mid.htmlAutorotation
If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.Putandtake
Is it possible to configure SMTP server to add message id automatically not to send it in application?Putandtake
yes, postfix for example: always_add_missing_headers (default: no)Autorotation
B
4

This one works for me (I also added a 'Date' line to the header because it was a spam issue to me as well). Based on this peace of code.

Here's my PHP array approach (using Pear's Mail and Mime libraries):

$headers = array(
   'From'       => $from,
   'Subject'    => $subject,
   'To'     => $to,
   'Cc'     => '',
   'Date'       => date('r'),
   'Message-ID' => sprintf("<%s.%s@%s>",
                                base_convert(microtime(), 10, 36),
                                base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36),
                                'yourdomain.com')
                );

Note that using $_SERVER['SERVER_NAME'] instead of literally 'yourdomain.com' won't work in php cli as commented out by Oleg on another answer.

Britanybritches answered 26/7, 2018 at 5:38 Comment(0)
C
0

I am using same MessageId to track the exchanged messages.

I fix the MessageId with:

$mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');
Chapple answered 20/7, 2015 at 2:7 Comment(0)
I
0

tl;dr; Do not use port 25 when sending email instead use port 587

When I was sending outbound email from my custom created golang email client using port 25 to my local postfix server with destination email address either gmail or google gsuite adddress I was seeing

Message ID  <[email protected]>

as viewed from destination email adddress in gmail Show Original ... However since I am using full TLS certs in both my golang email client and local postfix server, when I replace using port 25 with the secure port 587 in my outbound email client (postfix was already using TLS certs) then I get the proper

Message ID  <[email protected]>

NOTE - at no time am I defining an email header message-id infact the golang repo I'm using does not have an api call to define that header

Isocrates answered 9/11, 2018 at 16:52 Comment(0)
S
0

You missed the '<' and '>' brackets.

Schaab answered 16/6, 2020 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.