The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

DKIM in cPanel with PHPmailer clarification

Discussion in 'E-mail Discussions' started by martin MHC, Oct 3, 2016.

Tags:
  1. martin MHC

    martin MHC Member

    Joined:
    Sep 14, 2016
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Location:
    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?
     
    #1 martin MHC, Oct 3, 2016
    Last edited by a moderator: Oct 4, 2016
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  3. martin MHC

    martin MHC Member

    Joined:
    Sep 14, 2016
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Location:
    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.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  5. martin MHC

    martin MHC Member

    Joined:
    Sep 14, 2016
    Messages:
    15
    Likes Received:
    5
    Trophy Points:
    3
    Location:
    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
     
    cPanelMichael likes this.
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,723
    Likes Received:
    660
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page