2009-09-28 102 views
1

如何使用PHP「簽名」傳出的電子郵件?在PHP中籤名的電子郵件

我期待在適當的標題是:

signed-by mydomain.com 
+0

請解釋你到底想要什麼。你不只是想要簽名的標題 - 你想要域密鑰或類似的東西,對吧? – 2009-09-28 23:01:24

回答

3

如果我理解正確的話,你想用PHP生成一個簽名的電子郵件。

發送已簽名電子郵件的標準方式是S/MIME(另一種不太常見的方式是PGP)。 S/MIME基本上是一個包含CMS消息的base64編碼的MIME消息(CMS有時也被稱爲PKCS#7)。

從PHP執行此操作的一種方法是將PHP綁定到OpenSSL的openssl_pkcs7_sign

我不知道應該使用signed-by標頭。

+0

謝謝,這正是我需要的! :D – 2011-06-02 09:42:14

+0

這就是爲什麼您需要這些標題:https://support.google.com/mail/answer/180707?hl = zh_CN – 2014-02-09 09:12:52

0

如果你有一個.p12文件,那麼你可能需要從其中提取的公共證書和私鑰:

私鑰:

openssl pkcs12 -in <YOUR_FILE>.p12 -nocerts -out privateKey.pem 

公共證書:

openssl pkcs12 -in <YOUR_FILE>.p12 -clcerts -nokeys -out publicCert.pem 

然後你可以發送一個簽署的電子郵件與此PHP代碼:

<?php 

$data = "This is a test signed email"; 

// create a temporary file 
$fp = fopen("msg.txt", "w"); 
fwrite($fp, $data); 
fclose($fp); 


// sign the email 
openssl_pkcs7_sign("msg.txt", "signed.txt", 
    file_get_contents(realpath("publicCert.pem")), 
    array(file_get_contents(realpath("privateKey.pem")), '<YOUR_PASS>'), 
    array(
     "To" => "[email protected]", 
     "From: Jane Doe <[email protected]>", 
     "Subject" => "This is a test" 
     ) 
    ); 



exec(ini_get("sendmail_path") . " < signed.txt");