title: How to properly hash body and headers with PHP for dkim?
body: <p>I've gone through Eric Vyncke's PHP <a href="http://php-dkim.cvs.sourceforge.net/viewvc/php-dkim/php-dkim/" rel="nofollow noreferrer">dkim script</a> and copied how he was doing hashes for DKIM headers set in emails </p>
  
  <pre><code>$DKIM_bh = base64_encode(pack('H*', sha1($body)));
  </code></pre>
  
  <p>Would be used as so:</p>
  
  <pre><code>'bh='.$DKIM_bh.';'//...
  </code></pre>
  
  <p>However when I <a href="http://www.appmaildev.com/en/dkim/" rel="nofollow noreferrer">validate the email message</a> it tells me that the hash doesn't match.</p>
  
  <pre><code>$headers .= 'DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/simple; q=dns/txt; bh=';//...
  
  $body = 'Test PHP+SMTP authenticated email,3.';
  
  bh='.base64_encode(pack('H*', sha1($body))).';';//...
  </code></pre>
  
  <p>I'm not sure what I'm missing? <strong>How</strong> do I properly hash the body and headers so I can set the DKIM values for the header properly?</p>