{"id":57122,"date":"2022-10-25T03:01:35","date_gmt":"2022-10-24T17:01:35","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=57122"},"modified":"2022-10-25T05:56:53","modified_gmt":"2022-10-24T19:56:53","slug":"php-inline-html-gmail-duplicate-header-field-troubleshooting-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-inline-html-gmail-duplicate-header-field-troubleshooting-tutorial\/","title":{"rendered":"PHP Inline HTML Gmail Duplicate Header Field Troubleshooting Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/duplicate_to.gif\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"PHP Inline HTML Gmail Duplicate Header Field Troubleshooting Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/duplicate_to.gif\" title=\"PHP Inline HTML Gmail Duplicate Header Field Troubleshooting Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">PHP Inline HTML Gmail Duplicate Header Field Troubleshooting Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Exim Mail Server Troubleshooting Primer Tutorial' href='#emstpt'>Exim Mail Server Troubleshooting Primer Tutorial<\/a> represented a mail server level of issue with emailing hereabouts.<\/p>\n<p>Another level of issue with emailing can occur with our inhouse PHP created inline HTML emails to <a target=_blank title='Gmail' href='https:\/\/gmail.com'>Gmail<\/a>, where we&#8217;ve again used <a target=_blank title='Exim' href='https:\/\/www.exim.org\/'>Exim<\/a>&#8216;s exim_mainlog log file to discover &#8230;<\/p>\n<p><img src='http:\/\/www.rjmprogramming.com.au\/Mac\/duplicate_to.jpeg'><\/img><\/p>\n<p> &#8230; whereby we&#8217;d been, in the headers of the PHP <a target=_blank title='PHP mail function' href='https:\/\/www.php.net\/manual\/en\/function.mail.php'>mail<\/a> email message, specifying the &#8220;To:&#8221; field twice, and at the Gmail end, this email is blocked until we modified PHP <font color=blue>as per<\/font> &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\n                if ($message != \"\") {  \/\/ inline HTML<br \/>\n<br \/>\n \/\/ To send HTML mail, the Content-type header must be set<br \/>\n $hdrs[] = 'MIME-Version: 1.0';<br \/>\n if ($subd != \"\") {<br \/>\n $hdrs[] = 'Content-type: application\/pdf';<br \/>\n } else {<br \/>\n $hdrs[] = 'Content-type: text\/html; charset=iso-8859-1';<br \/>\n }<br \/>\n<br \/>\n \/\/ Additional headers<br \/>\n <font color=blue>if (strpos(strtolower($to), \"@gmail.com\") === false) { <\/font>\/\/!in_array('To: ' . $to, $hdrs)) {<br \/>\n $hdrs[] = 'To: ' . $to;<br \/>\n <font color=blue>}<\/font><br \/>\n $hdrs[] = 'From: ' . $fromer;<br \/>\n<br \/>\n if ($cc != \"\") { $hdrs[] = 'CC: ' . $cc; }<br \/>\n if ($bcc != \"\") { $hdrs[] = 'BCC: ' . $bcc; }<br \/>\n $hdrs[] = 'Reply-To: ' . $fromer;<br \/>\n<br \/>\n \/\/ Mail it<br \/>\n $fflist=\"inline HTML\";<br \/>\n zmail($to,  $subject, $message, implode(\"\\r\\n\", $hdrs));<br \/>\n                } else {<br \/>\n                zmail($to, $subject, \"\", $headers);<br \/>\n                }<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p> &#8230; in <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php------------------------GETME'>the changed inhouse PHP email helper<\/a> <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/emailhtml.php------------------------GETME'>emailhtml.php<\/a> to <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/duplicate_to.gif\" title=\"Tutorial picture\">remedy this situation<\/a>.<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>Though the exim_mainlog panned out to be telling the truth, we wanted to see the issue for ourselves.  Fortuitously, yesterday&#8217;s allowed through inline HTML email <a href='#goodi'>example<\/a> was also an example of leniency at <a target=_blank title='Gmail' href='https:\/\/gmail.com'>Gmail<\/a> <font size=1>(as well as engendering a false sense of security)<\/font> to allow through and we were able to reference that email&#8217;s vertical &#8220;<span style='display:inline-block;transform:rotate(90deg);'>&nbsp;&#8230;<\/span>&#8221; menu&#8217;s &#8220;Show original&#8221; suboption to <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/duplicate_to.gif\" title=\"Tutorial picture\">see the duplicate &#8216;To:&#8217; header fields<\/a> that would later cause another blockage.  The &#8220;Show original&#8221; suboption here can be very useful.<\/p>\n<p>And on macOS or Linux command line, in dynamic logging situations, the (in our case) &#8230;<\/p>\n<p><code><br \/>\n# tail -f \/var\/log\/exim_mainlog<br \/>\n<\/code><\/p>\n<p> &#8230; followed by the sending of an inhouse PHP mail created inline HTML email, and then after a bit, control-C back at the tail operation, was a good way to investigate a little subset of relevant logging activity, via the macOS Terminal application scrolling (up) abilities.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/php-inline-html-gmail-duplicate-header-field-troubleshooting-tutorial\/'>PHP Inline HTML Gmail Duplicate Header Field Troubleshooting Tutorial<\/a>.<\/p-->\n<hr>\n<p id='emstpt'>Previous relevant <a target=_blank title='Exim Mail Server Troubleshooting Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/exim-mail-server-troubleshooting-primer-tutorial\/'>Exim Mail Server Troubleshooting Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/exim_better_verbose_delivered.jpeg\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Exim Mail Server Troubleshooting Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/exim_better_verbose_delivered.jpeg\" title=\"Exim Mail Server Troubleshooting Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Exim Mail Server Troubleshooting Primer Tutorial<\/p><\/div>\n<p><a target=_blank title='Exim' href='https:\/\/www.exim.org\/'>Exim Internet Mailer<\/a>, as our Mail Server software here at this RJM Programming web server, has seemed an enigma, especially when, a while back <font size=1>(tut, tut)<\/font> it went quite quiet sending out emails to <a target=_blank title='Gmail' href='https:\/\/gmail.com'>Gmail<\/a> recipients, at the very least.  Take a look at the directory structure of exim, and you might join me!<\/p>\n<p>However, today, we stepped back and got past our vague &#8220;spam&#8221; theories, and got inspiration from the excellent advice at <a target=_blank href='https:\/\/makandracards.com\/operations\/36349-send-a-testmail-via-exim'>send a testmail via exim &#8211; makandra Operations<\/a>, thanks, to try, at our RJM Programming ssh access terminal command line session, typing &#8230;<\/p>\n<p><code><br \/>\n# exim -v rmetcalfe15@gmail.com<br \/>\nFrom: user@domain.name<br \/>\nSubject: Foobar<br \/>\nText Text Text<br \/>\n<br \/>\nI like Pie!<br \/>\n<font size=1>&lt;control-D&gt;<\/font><br \/>\n<\/code><\/p>\n<p> &#8230; ended by (macOS keyboard) control-D to get to see the exim error logging dynamically.  Was it the <font size=1>monochrome<\/font> colour and <font size=1>scrolling<\/font> movement that finally got me to take my head out of the sand?!<\/p>\n<p>The logging that followed reasoned &#8230;<\/p>\n<blockquote><p>\n  SMTP error from remote mail server after end of data: host gmail-smtp-in.l.google.com: 421-4.7.0 This message does not pass authentication checks (SPF and DKIM both do\\n421-4.7.0 not pass). SPF check does not pass\\n421-4.7.0 with ip.To best protect our users from spam, the\\n421-4.7.0 message has been blocked. Please visit\\n421-4.7.0  https:\/\/support.google.com\/mail\/answer\/81126#authentication for more\\n421 4.7.0 information.\n<\/p><\/blockquote>\n<p> &#8230; and gave me a link to follow up with at <a target=_blank href='https:\/\/support.google.com\/mail\/answer\/81126#authentication' title='Prevent mail to Gmail users from being blocked or sent to spam - Gmail Help'>Prevent mail to Gmail users from being blocked or sent to spam &#8211; Gmail Help<\/a>, thanks, which honed my attention to possible need for, first off &#8230;<\/p>\n<ul>\n<li>SPF record<\/li>\n<li>DKIM record<\/li>\n<\/ul>\n<p> &#8230; ahead of realizing, sadly, that no cPanel menu options directly attended to this on the RJM Programming&#8217;s cPanel, but a great link <a target=_blank href='https:\/\/www.hostnextra.com\/kb\/add-spf-records-and-dkim-keys-in-cpanel-using-cli\/' title='Add SPF Records and DKIM keys in cPanel Using CLI HostnExtra'>Add SPF Records and DKIM keys in cPanel Using CLI HostnExtra<\/a>, thanks, coming to my aid, filling me with enough confidence, that its suggested &#8230;<\/p>\n<blockquote><p>\n# \/usr\/local\/cpanel\/bin\/dkim_keys_install [user]<br \/>\n# \/usr\/local\/cpanel\/bin\/spf_installer [user]\n<\/p><\/blockquote>\n<p> &#8230; &#8220;single user&#8221; may indeed suit RJM Programming for three reasons &#8230;<\/p>\n<ol>\n<li>going &#8230;<br \/>\n<code><br \/>\n# ls -l \/var\/cpanel\/users<br \/>\n<\/code><br \/>\n &#8230; implied just the one [user] needed, to worry about\n<\/li>\n<li>\/usr\/local\/cpanel\/bin\/dkim_keys_install script exists<\/li>\n<li>\/usr\/local\/cpanel\/bin\/spf_installer script exists<\/li>\n<\/ol>\n<p>So we plucked up the courage to proceed with those excellent suggested commands just above (substituting [user] for our RJM Programming web site&#8217;s user name), with great success!<\/p>\n<p><code><br \/>\n# exim -v rmetcalfe15@gmail.com<br \/>\nLOG: MAIN<br \/>\n  cwd=\/var\/cpanel\/users 3 args: exim -v rmetcalfe15@gmail.com<br \/>\nFrom: user@domain.name<br \/>\nSubject: Foobar<br \/>\nText Text Text<br \/>\n<br \/>\nI like Pie!<br \/>\nLOG: MAIN<br \/>\n  &lt;= user@domain.name U=root P=local S=392 T=\"Foobar\"<br \/>\n [\/var\/cpanel\/users]# LOG: MAIN<br \/>\n  cwd=\/var\/spool\/exim 4 args: \/usr\/sbin\/exim -v -Mc 1omQjv-000CHd-L7<br \/>\ndelivering 1omQjv-000CHd-L7<br \/>\nConnecting to gmail-smtp-in.l.google.com [an.ip.address]:25 ... connected<br \/>\n  SMTP&lt;&lt; 220 mx.google.com ESMTP [google-code].65 - gsmtp<br \/>\n  SMTP&gt;&gt; EHLO vs-rmetcalfe.au.syrahost.com<br \/>\n  SMTP&lt;&lt; 250-mx.google.com at your service, [ip.rjm]<br \/>\n         250-SIZE 157286400<br \/>\n         250-8BITMIME<br \/>\n         250-STARTTLS<br \/>\n         250-ENHANCEDSTATUSCODES<br \/>\n         250-PIPELINING<br \/>\n         250-CHUNKING<br \/>\n         250 SMTPUTF8<br \/>\n  SMTP&gt;&gt; STARTTLS<br \/>\n  SMTP&lt;&lt; 220 2.0.0 Ready to start TLS<br \/>\n  SMTP&gt;&gt; EHLO domain.name<br \/>\n  SMTP&lt;&lt; 250-mx.google.com at your service, [ip.rjm]<br \/>\n         250-SIZE 157286400<br \/>\n         250-8BITMIME<br \/>\n         250-ENHANCEDSTATUSCODES<br \/>\n         250-PIPELINING<br \/>\n         250-CHUNKING<br \/>\n         250 SMTPUTF8<br \/>\n  SMTP&gt;&gt; MAIL FROM:&lt;user@domain.name&gt; SIZE=1426<br \/>\n  SMTP&gt;&gt; RCPT TO:&lt;rmetcalfe15@gmail.com&gt;<br \/>\n  SMTP&gt;&gt; DATA<br \/>\n  SMTP&lt;&lt; 250 2.1.0 OK [google-code].65 - gsmtp<br \/>\n  SMTP&lt;&lt; 250 2.1.5 OK [google-code].65 - gsmtp<br \/>\n  SMTP&lt;&lt; 354  Go ahead [google-code].65 - gsmtp<br \/>\n  SMTP&gt;&gt; writing message and terminating \".\"<br \/>\n  SMTP&lt;&lt; 250 2.0.0 OK  1666492215 [google-code].65 - gsmtp<br \/>\n  SMTP&gt;&gt; QUIT<br \/>\nLOG: MAIN<br \/>\n  =&gt; rmetcalfe15@gmail.com R=lookuphost T=remote_smtp H=gmail-smtp-in.l.google.com [an.ip.address] X=UNKNOWN:ECDHE-ECDSA-AES128-GCM-SHA256:128<br \/>\nLOG: MAIN<br \/>\n  Completed<br \/>\n<\/code><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/exim_better_verbose_delivered.jpeg\"><\/img><\/p>\n<p>Yayyyyyy!<\/p>\n<p><img decoding=\"async\" id=goodi src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/exim_better_verbose_inline_html_delivered.jpg\" onclick=\"window.open('\/\/www.rjmprogramming.com.au\/HTMLCSS\/cmyk_rgb.html','_blank');\"><\/img><\/p>\n<p>And yayyyyyy to an inline HTML email scenario too!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d57109' onclick='var dv=document.getElementById(\"d57109\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/gmail\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d57109' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d57122' onclick='var dv=document.getElementById(\"d57122\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/headers\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d57122' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Exim Mail Server Troubleshooting Primer Tutorial represented a mail server level of issue with emailing hereabouts. Another level of issue with emailing can occur with our inhouse PHP created inline HTML emails to Gmail, where we&#8217;ve again used Exim&#8216;s &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-inline-html-gmail-duplicate-header-field-troubleshooting-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[85,2840,195,233,234,249,327,4110,4114,380,1929,394,2751,503,3715,1807,716,717,738,2240,4113,932,1114,3125,4111,1190,1511,4109,1319,1411,1426],"class_list":["post-57122","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-apache","tag-authentication","tag-centos","tag-command","tag-command-line","tag-configuration","tag-did-you-know","tag-dkim","tag-duplicate","tag-email","tag-error","tag-error-log","tag-exim","tag-gmail","tag-headers","tag-link","tag-log","tag-logging","tag-mail","tag-mail-server","tag-original","tag-php","tag-security","tag-spam","tag-spf","tag-ssh","tag-tail","tag-test-message","tag-tutorial","tag-web-server","tag-whm"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57122"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=57122"}],"version-history":[{"count":23,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57122\/revisions"}],"predecessor-version":[{"id":57158,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/57122\/revisions\/57158"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=57122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=57122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=57122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}