DKIM in cPanel with PHPmailer clarification

martin MHC

Well-Known Member
Sep 14, 2016
292
69
78
UK
cPanel Access Level
Root Administrator
Hello
I have just set up SPF and DKIM in my CPanel (v58) account, and would like some clarification on its usage.

I use emailing via PHP with the PHPMailer class ( github.com/PHPMailer/PHPMailer ) which has various methods involving setting DKIM settings within the class, however from reading other website (and CPanel Forum) posts, I have not found a clear answer to the following query.

Precursor:
My website(s) have their DN controlled by WHM so everything DNS wise is on then WHM/CPanel system. No 3rd Party DNS.

I have found various literature ( stackoverflow.com/a/24464694/3536236 ) stating that PHPMailer can add DKIM details to outgoing emails.

Various comments etc. seem to imply that I only need to add DKIM details to PHPMailer if the DNS is a 3rd Party system.

So.... As my whole system is within WHM, do I need to add DKIM details to PHPMailer class?
If so, how do I find out where the DKIM keys are located (as this file location is required by PHPMailer, please see StackOverfow link above).

If not, am I right in assuming that the DKIM details are appended to the email as it is sent from the server automatically?
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hello,

If you use a PHP script, you should manually add the DKIM signature to the message headers. Some examples of this are discussed at:

Setting up DomainKeys/DKIM in a PHP-based SMTP client

The actual keys are stored for each domain name in the following directory:

/var/cpanel/domain_keys/private/

Thank you.
 

martin MHC

Well-Known Member
Sep 14, 2016
292
69
78
UK
cPanel Access Level
Root Administrator
Thanks for the feedback, Michael.

I have a query for this -- my PHP script (quite rightly) does not have access to this folder, so the script can not send out authorised DKIM mails [class uses file_get_contents function on the key file when sending mail). The obvious solution would be to copy/paste the key file into the account area, however I'm wary of the [obvious] risks of doing that (not least key leakage but also that if the cpanel key gets updated in the future then I'd need to manually update the account-copy of said key).

Can you give me a pointer as to the safest (non-duplication?) way to share the keyfile with PHP.

Many thanks.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Have you tried setting up a PHP test script without the call to the private DKIM key location? Exim should automatically detect the DKIM key path when sending via PHP using SMTP Authentication on the cPanel server:

Authentication - Documentation - cPanel Documentation

Thank you.
 

martin MHC

Well-Known Member
Sep 14, 2016
292
69
78
UK
cPanel Access Level
Root Administrator
Hi Michael, thanks for the feedback. I have come to a conclusion that PHP DKIM references are only required when using a mailer that is on *another* server, such as people who send PHP emails via gmail.com etc or have seperate data- and email- servers. I think that DKIM is handled entirely above the PHP level when it's all on the same server.

Tests show that with all emails sent DKIM and SPF checks are both passed.

So;
As my whole system is within WHM, do I need to add DKIM details to PHPMailer class? -- NO. If your mailer server is the same server as the DKIM details are setup on then you do not need to add any DKIM details to the PHPMailer class, this is all handled outside of PHP -by the same authenticated server- before email launch.

Cheers
 
  • Like
Reactions: cPanelMichael

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hello,

I'm happy to see the email passed both DKIM and SPF tests. Thank you for testing it out and updating us with the outcome.