Wednesday, February 21, 2018

How to resolve DMARC and DKIM pass in mailer header in php

Hey    , Guy

I am sharing my experienced which I faced lot of effort to resolve the DKIM and DMARC fail issue on email sent.

Finally I resolved the issue using changing the header below and validate the html tag in your email body.

Here is the result of pass by google and test mailer

SPF:PASS with IP Learn more
DKIM:'PASS' with domain Learn more

function sendNewsLetter($id='', $to_name='', $to_address=''){

    $from_name    = 'Phptechnicalgroups';
    $from_address = '';
    $reply_address = '';
//hiddenUrl variable call when user read the email to identify
 $hiddenUrl      = ''.$id;

$maildescription ='<html>


<body style="margin: 0; padding: 0;">
    <div style="display: none;">
        <img alt="" src="'.$hiddenUrl.'" width="0px" height="0px">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Phptechnicalgroup - Social Hub Updates - January 2018</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
       $subject  = "Email Subject";
    $mime_boundary = "----php technical group----".MD5(TIME().$id.TIME());
    $additional ='';
    $messageid = $_SERVER['REQUEST_TIME'] . md5($_SERVER['REQUEST_TIME']) .$id. '@' . $_SERVER['SERVER_NAME'];
    $headers  = "MIME-Version: 1.0" . "\r\n";
    $headers .= 'Return-Path: Intel Network Builders <>'."\r\n";
    $headers .= 'X-Mailer: PHP v'.phpversion()."\r\n";
    $headers .= 'Message-ID:<'.$messageid.'>'."\r\n";
    $headers .= 'X-Originating-IP:'.$_SERVER['SERVER_ADDR']."\r\n";
    $headers .= 'List-Unsubscribe: <>'."\r\n";
    $headers .= 'From: php technical group <>' . "\r\n";
    $headers .= 'Bcc:  <>' . "\r\n";
    $headers .= 'Reply-To: php technical group <>' . "\r\n";
    $headers .= "Content-Type: multipart/mixed; boundary=\"$mime_boundary\"\r\n";

//Create Email Body (HTML)
    $message = "--$mime_boundary\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";
    $message .= "<html>\n";
    $message .= "<body>\n";
    $message .= $maildescription;
    $message .= "</body>\n";
    $message .= "</html>\n";
    $message .= "--$mime_boundary\n";
    $mailsent = mail($to_address, $subject, $message, $headers,'-f'.$additional);
    return ($mailsent)?(true):(false);

Hopefully it will help you , thank you!

No comments:

Post a Comment