adding DKIM on PHP email header

Viewed 4788

I am trying to add a DKIM for the emails which are sent from my server. I added the public key on the DNS records (as a TXT records) of my domain, but I cannot find where to add the private key. It seems it should go into the email headers. This is how the code looks like:

    $_headers = array(
        'From' => $config['smtp_from'],
        'To' => $to,
        'Subject' => $subject
    );

    if ($html) {
        $_headers['MIME-Version'] = '1.0';
        $_headers['Content-type'] = 'text/html; charset=UTF-8';
    }

    if ($headers) {
        foreach ($headers as $key => $val) {
            $_headers[$key] = $val;
        }
    }

    $smtp = Mail::factory('smtp', array(
        'host' => $config['smtp_host'],
        'auth' => false,
        'username' => $config['smtp_user'],
        'password' => $config['smtp_pass']
    ));

    $mail = $smtp->send($to, $_headers, $message);

    if (PEAR::isError($mail)) {
        return false;
    } else {
        log_add('', 'To: ' . $to . '<br />Subject: ' . $subject, 'email');
        return true;
     }

Can someone please advise where the private key should be added? The problem is that the emails sent to Gmail recipients are going to Spam, so I understand that a DKIM should fix this.

I am using PEAR email to send emails from the server.

0 Answers
Related