Send mail in phpmailer using DKIM Keys
Asked Answered
A

2

23

Currents i am using phpmailer to send mail's. now how its possible to send email in phpmailer with DKIM keys

i search in phpmailer Class file and i found the below code

    /**
     * DKIM selector.
     * @type string
     */
    public $DKIM_selector = '';

    /**
     * DKIM Identity.
     * Usually the email address used as the source of the email
     * @type string
     */
    public $DKIM_identity = '';

    /**
     * DKIM passphrase.
     * Used if your key is encrypted.
     * @type string
     */
    public $DKIM_passphrase = '';

    /**
     * DKIM signing domain name.
     * @example 'example.com'
     * @type string
     */
    public $DKIM_domain = '';

    /**
     * DKIM private key file path.
     * @type string
     */
    public $DKIM_private = '';

Can i know how its possible.

Are answered 28/6, 2014 at 3:57 Comment(2)
What specifically are you having trouble with? The comments seem fully explanatory.Doubleheader
I experimented with this but couldn't make it work. I opted for an OpenDKIM filter for Sendmail which has the advantage that all the outbound mail is signedMuniments
M
46

If you take a look in the PHPMailer unit tests, there is an example of how to set up DKIM.

Here are the basics beyond what you already need to do to send a message (obviously change the domain, key path and selector to match your config, and add a passphrase if you use one); this also assumes that you are intending to sign using the same identifier as your From address:

$mail->DKIM_domain = 'example.com';
$mail->DKIM_private = '/path/to/my/private.key';
$mail->DKIM_selector = 'phpmailer';
$mail->DKIM_passphrase = '';
$mail->DKIM_identity = $mail->From;

When you send() the message (and not before), it will use these settings to generate a DKIM signature.

Mudd answered 28/6, 2014 at 7:34 Comment(12)
from where i can get the key path /path/to/my/private.key and what is this $mail->DKIM_passphraseAre
If you look at the unit test code it includes key creation, but if you're signing for DKIM you will have already done that and you will have a key somewhere, but I don't know where you've put it! When you create a key pair, you can optionally encrypt the key using a passphrase, and anything that needs to use the key needs to be able to decrypt it, so it needs the passphrase, and this is where you put it. If you don't encrypt your key (as is common on servers), you don't need this.Mudd
Is the DKIM_selector always 'phpmailer' ?Lanceted
No, it's whatever you set DKIM_selector to!Mudd
Thanks for the help on this. For a full guide on how to setup DKIM before you get to this point i put together a guide yomotherboard.com/how-to-setup-email-server-dkim-keysFootton
DKIM_identifier is now DKIM_identity (PHPMailer 5.2.13)Dominickdominie
DKIM_selector is the selector key setup on your DNS TXT record. It's not always phpmailer as in the example.Humidistat
To use a private key string instead of setting a path to a file, you can simply specify $mail -> DKIM_private_string property on your phpMailer object.Delouse
@Mudd my web hosting server automatically gives me a public DKIM key...where do I find it's associated 'private' key for $mail->DKIM_private = '/path/to/my/private.key';?Complaisance
I've no idea! Ask them?Mudd
Oh okay, I thought that it's not unusual for a web hosting server to store/provide the DKIM keysComplaisance
@Delouse how do i use DKIM_private_string ? base64encode the key ?Trapezohedron
B
2

I have the following experience:

  1. The pair of the keys generated at http://dkim.worxware.com/createkeys.php is probably intended for the SHA1, while the latest version 5.2.14 of the class.phpmailer.php is intended for SHA256.
    The example above was not functional.
  2. I changed all settings and functions in the class.phpmailer.php from SHA256 on SHA1 (I replaced simply all strings SHA256 with the strings SHA1).
    My PHP script for DKIM signature has became functional.
Bara answered 29/2, 2016 at 10:13 Comment(2)
Took me a couple of hours to find out this was my issue to! Very frustrating! I used this site to generate my keys socketlabs.com/domainkey-dkim-generation-wizard. Working fine with the latest version of phpmailer (5.2.14)Tournai
Avoid the SHA1 family of functions. Practical attacks on SHA1 were published earlier this year (shattered.io). There are plenty of instructions on how to generate a DKIM keypair using openssl. Also, it is generally a bad idea to have a third party website generate any security keys for you. If they store the key, they can impersonate you. Instead, generate it offline using openssl.Onfre

© 2022 - 2024 — McMap. All rights reserved.