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









up vote
14
down vote

favorite
7












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



Message-Id: <5100054f.a489440a.5d93.6a70SMTPIN_ADDED_MISSING@mx.google.com>


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:



38D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com


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










share|improve this question

























    up vote
    14
    down vote

    favorite
    7












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



    Message-Id: <5100054f.a489440a.5d93.6a70SMTPIN_ADDED_MISSING@mx.google.com>


    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:



    38D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com


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










    share|improve this question























      up vote
      14
      down vote

      favorite
      7









      up vote
      14
      down vote

      favorite
      7






      7





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



      Message-Id: <5100054f.a489440a.5d93.6a70SMTPIN_ADDED_MISSING@mx.google.com>


      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:



      38D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com


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










      share|improve this question













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



      Message-Id: <5100054f.a489440a.5d93.6a70SMTPIN_ADDED_MISSING@mx.google.com>


      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:



      38D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com


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







      php email smtp zend-mail






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 23 '13 at 16:00









      Oleg

      1,29842653




      1,29842653






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          15
          down vote













          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:



          1358961017-677533f745f613447d06de25e7fa4d32@yourdomain.com





          share|improve this answer




















          • Do you mean that absense of Message_Id increases chances of going to spam?
            – Oleg
            Jan 23 '13 at 17:26










          • Could message_id contain domain of smpt server that sends email?
            – Oleg
            Jan 23 '13 at 17:26










          • Doesn't smpt server add message_id automatically, it should be added form the application, right?
            – Oleg
            Jan 23 '13 at 17:28






          • 1




            Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
            – Sammitch
            Jan 23 '13 at 17:31






          • 1




            Using $_SERVER['SERVER_NAME'] won't work in php cli.
            – Oleg
            Jan 24 '13 at 13:36

















          up vote
          6
          down vote













          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.






          share|improve this answer


















          • 1




            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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
            – Oleg
            Jan 23 '13 at 16:58










          • Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
            – Oleg
            Jan 23 '13 at 17:09










          • 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.html
            – clover
            Jan 23 '13 at 17:17











          • If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
            – Oleg
            Jan 24 '13 at 4:16










          • I improved my answer.
            – clover
            Jan 24 '13 at 8:54

















          up vote
          1
          down vote













          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),
          'youdomain.com')
          );


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






          share|improve this answer





























            up vote
            0
            down vote













            I am using same MessageId to track the exchanged messages.



            I fix the MessageId with:



            $mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');





            share|improve this answer





























              up vote
              0
              down vote













              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 <5be55db9.1c69fb81.d0444.d894SMTPIN_ADDED_MISSING@mx.google.com>


              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 <20181109163255.F164D8E9588@mail.myexample.com>


              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






              share|improve this answer






















                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                 

                draft saved


                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14483861%2fwhats-the-issue-with-message-id-in-email-sent-by-php%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                15
                down vote













                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:



                1358961017-677533f745f613447d06de25e7fa4d32@yourdomain.com





                share|improve this answer




















                • Do you mean that absense of Message_Id increases chances of going to spam?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Could message_id contain domain of smpt server that sends email?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Doesn't smpt server add message_id automatically, it should be added form the application, right?
                  – Oleg
                  Jan 23 '13 at 17:28






                • 1




                  Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
                  – Sammitch
                  Jan 23 '13 at 17:31






                • 1




                  Using $_SERVER['SERVER_NAME'] won't work in php cli.
                  – Oleg
                  Jan 24 '13 at 13:36














                up vote
                15
                down vote













                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:



                1358961017-677533f745f613447d06de25e7fa4d32@yourdomain.com





                share|improve this answer




















                • Do you mean that absense of Message_Id increases chances of going to spam?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Could message_id contain domain of smpt server that sends email?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Doesn't smpt server add message_id automatically, it should be added form the application, right?
                  – Oleg
                  Jan 23 '13 at 17:28






                • 1




                  Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
                  – Sammitch
                  Jan 23 '13 at 17:31






                • 1




                  Using $_SERVER['SERVER_NAME'] won't work in php cli.
                  – Oleg
                  Jan 24 '13 at 13:36












                up vote
                15
                down vote










                up vote
                15
                down vote









                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:



                1358961017-677533f745f613447d06de25e7fa4d32@yourdomain.com





                share|improve this answer












                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:



                1358961017-677533f745f613447d06de25e7fa4d32@yourdomain.com






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 23 '13 at 17:19









                Sammitch

                19.4k42863




                19.4k42863











                • Do you mean that absense of Message_Id increases chances of going to spam?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Could message_id contain domain of smpt server that sends email?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Doesn't smpt server add message_id automatically, it should be added form the application, right?
                  – Oleg
                  Jan 23 '13 at 17:28






                • 1




                  Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
                  – Sammitch
                  Jan 23 '13 at 17:31






                • 1




                  Using $_SERVER['SERVER_NAME'] won't work in php cli.
                  – Oleg
                  Jan 24 '13 at 13:36
















                • Do you mean that absense of Message_Id increases chances of going to spam?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Could message_id contain domain of smpt server that sends email?
                  – Oleg
                  Jan 23 '13 at 17:26










                • Doesn't smpt server add message_id automatically, it should be added form the application, right?
                  – Oleg
                  Jan 23 '13 at 17:28






                • 1




                  Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
                  – Sammitch
                  Jan 23 '13 at 17:31






                • 1




                  Using $_SERVER['SERVER_NAME'] won't work in php cli.
                  – Oleg
                  Jan 24 '13 at 13:36















                Do you mean that absense of Message_Id increases chances of going to spam?
                – Oleg
                Jan 23 '13 at 17:26




                Do you mean that absense of Message_Id increases chances of going to spam?
                – Oleg
                Jan 23 '13 at 17:26












                Could message_id contain domain of smpt server that sends email?
                – Oleg
                Jan 23 '13 at 17:26




                Could message_id contain domain of smpt server that sends email?
                – Oleg
                Jan 23 '13 at 17:26












                Doesn't smpt server add message_id automatically, it should be added form the application, right?
                – Oleg
                Jan 23 '13 at 17:28




                Doesn't smpt server add message_id automatically, it should be added form the application, right?
                – Oleg
                Jan 23 '13 at 17:28




                1




                1




                Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
                – Sammitch
                Jan 23 '13 at 17:31




                Like I said, 'Any malformed or missing headers will add to the "spam score"'. SMTP servers should add it, but yours clearly is not.
                – Sammitch
                Jan 23 '13 at 17:31




                1




                1




                Using $_SERVER['SERVER_NAME'] won't work in php cli.
                – Oleg
                Jan 24 '13 at 13:36




                Using $_SERVER['SERVER_NAME'] won't work in php cli.
                – Oleg
                Jan 24 '13 at 13:36












                up vote
                6
                down vote













                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.






                share|improve this answer


















                • 1




                  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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
                  – Oleg
                  Jan 23 '13 at 16:58










                • Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
                  – Oleg
                  Jan 23 '13 at 17:09










                • 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.html
                  – clover
                  Jan 23 '13 at 17:17











                • If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
                  – Oleg
                  Jan 24 '13 at 4:16










                • I improved my answer.
                  – clover
                  Jan 24 '13 at 8:54














                up vote
                6
                down vote













                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.






                share|improve this answer


















                • 1




                  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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
                  – Oleg
                  Jan 23 '13 at 16:58










                • Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
                  – Oleg
                  Jan 23 '13 at 17:09










                • 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.html
                  – clover
                  Jan 23 '13 at 17:17











                • If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
                  – Oleg
                  Jan 24 '13 at 4:16










                • I improved my answer.
                  – clover
                  Jan 24 '13 at 8:54












                up vote
                6
                down vote










                up vote
                6
                down vote









                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.






                share|improve this answer














                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.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 24 '13 at 8:53

























                answered Jan 23 '13 at 16:53









                clover

                3,40711022




                3,40711022







                • 1




                  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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
                  – Oleg
                  Jan 23 '13 at 16:58










                • Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
                  – Oleg
                  Jan 23 '13 at 17:09










                • 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.html
                  – clover
                  Jan 23 '13 at 17:17











                • If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
                  – Oleg
                  Jan 24 '13 at 4:16










                • I improved my answer.
                  – clover
                  Jan 24 '13 at 8:54












                • 1




                  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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
                  – Oleg
                  Jan 23 '13 at 16:58










                • Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
                  – Oleg
                  Jan 23 '13 at 17:09










                • 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.html
                  – clover
                  Jan 23 '13 at 17:17











                • If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
                  – Oleg
                  Jan 24 '13 at 4:16










                • I improved my answer.
                  – clover
                  Jan 24 '13 at 8:54







                1




                1




                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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
                – Oleg
                Jan 23 '13 at 16:58




                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: 8D1C1FD-3C35-4568-925C-FC46CAC0DE8A@sendinghost.com?
                – Oleg
                Jan 23 '13 at 16:58












                Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
                – Oleg
                Jan 23 '13 at 17:09




                Do you mean that if there is not message id in sent email, receving email generate it and adds to the message?
                – Oleg
                Jan 23 '13 at 17:09












                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.html
                – clover
                Jan 23 '13 at 17:17





                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.html
                – clover
                Jan 23 '13 at 17:17













                If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
                – Oleg
                Jan 24 '13 at 4:16




                If SMTP server I send it from generates it why does it sets domain of google but not domain of smtp that sends it.
                – Oleg
                Jan 24 '13 at 4:16












                I improved my answer.
                – clover
                Jan 24 '13 at 8:54




                I improved my answer.
                – clover
                Jan 24 '13 at 8:54










                up vote
                1
                down vote













                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),
                'youdomain.com')
                );


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






                share|improve this answer


























                  up vote
                  1
                  down vote













                  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),
                  'youdomain.com')
                  );


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






                  share|improve this answer
























                    up vote
                    1
                    down vote










                    up vote
                    1
                    down vote









                    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),
                    'youdomain.com')
                    );


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






                    share|improve this answer














                    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),
                    'youdomain.com')
                    );


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







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 2 at 4:31

























                    answered Jul 26 at 5:38









                    Heitor

                    376424




                    376424




















                        up vote
                        0
                        down vote













                        I am using same MessageId to track the exchanged messages.



                        I fix the MessageId with:



                        $mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');





                        share|improve this answer


























                          up vote
                          0
                          down vote













                          I am using same MessageId to track the exchanged messages.



                          I fix the MessageId with:



                          $mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');





                          share|improve this answer
























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            I am using same MessageId to track the exchanged messages.



                            I fix the MessageId with:



                            $mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');





                            share|improve this answer














                            I am using same MessageId to track the exchanged messages.



                            I fix the MessageId with:



                            $mail->MessageID =sprintf('<%s@%s>', $myMessageID, 'myserver');






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jul 20 '15 at 2:17









                            Andrew Medico

                            17.5k84770




                            17.5k84770










                            answered Jul 20 '15 at 2:07









                            Flavio Ariano

                            413




                            413




















                                up vote
                                0
                                down vote













                                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 <5be55db9.1c69fb81.d0444.d894SMTPIN_ADDED_MISSING@mx.google.com>


                                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 <20181109163255.F164D8E9588@mail.myexample.com>


                                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






                                share|improve this answer


























                                  up vote
                                  0
                                  down vote













                                  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 <5be55db9.1c69fb81.d0444.d894SMTPIN_ADDED_MISSING@mx.google.com>


                                  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 <20181109163255.F164D8E9588@mail.myexample.com>


                                  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






                                  share|improve this answer
























                                    up vote
                                    0
                                    down vote










                                    up vote
                                    0
                                    down vote









                                    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 <5be55db9.1c69fb81.d0444.d894SMTPIN_ADDED_MISSING@mx.google.com>


                                    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 <20181109163255.F164D8E9588@mail.myexample.com>


                                    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






                                    share|improve this answer














                                    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 <5be55db9.1c69fb81.d0444.d894SMTPIN_ADDED_MISSING@mx.google.com>


                                    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 <20181109163255.F164D8E9588@mail.myexample.com>


                                    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







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 9 at 17:03

























                                    answered Nov 9 at 16:52









                                    Scott Stensland

                                    15.3k75371




                                    15.3k75371



























                                         

                                        draft saved


                                        draft discarded















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f14483861%2fwhats-the-issue-with-message-id-in-email-sent-by-php%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown