0
A
回答
0
我設法找到一個解決這個使用PHPMailer的,它適用於常規PHP爲好。它會對郵件進行簽名和加密,我無法找到一種方式來處理PHPMailer(簽名和加密)簽名,所以我在class.phpmailer.php中添加了一些代碼。它仍然需要添加一些錯誤處理來防止加密錯誤,但目前爲止效果不錯。
爲CakePHP的2.X:
App::import('Vendor','PHPMailer/PHPMailerAutoload');
:
下載PHPMailer的,並把它添加到您的供應商目錄(PROJECT_NAME /應用/供應商)
在你的函數的開頭添加此行
從這裏它的PHP或CakePHP相同:
$mail = new PHPMailer();
$mail->setFrom('[email protected]', 'Intranet');
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'Ricardo V');
//Set the subject line
$mail->Subject = 'PHPMailer signing test';
//Replace the plain text body with one created manually
$mail->Body = "some encrypted text...";
//Attach an image file
$mail->addAttachment('D:/path_to_file/test.pdf');
$mail->sign(
'app/webroot/cert/cert.crt', //The location of your certificate file
'app/webroot/cert/private.key', //The location of your private key
file
'password', //The password you protected your private key with (not
//the Import Password! may be empty but parameter must not be omitted!)
'app/webroot/cert/certchain.pem', //the certificate chain.
'1', //Encrypt the email as well, (1 = encrypt, 0 = dont encrypt)
'app/webroot/cert/rvarilias.crt'//The location of public certificate
//to encrypt the email with.
);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
然後,我們需要m AKE一些變化class.phpmailer.php
取代從2368行到2390搭配:
$sign = @openssl_pkcs7_sign(
$file,
$signed,
'file://' . realpath($this->sign_cert_file),
array('file://' . realpath($this->sign_key_file),
$this->sign_key_pass),
null,
PKCS7_DETACHED,
$this->sign_extracerts_file
);
if ($this->encrypt_file == 1) {
$encrypted = tempnam(sys_get_temp_dir(), 'encrypted');
$encrypt = @openssl_pkcs7_encrypt(
$signed,
$encrypted,
file_get_contents($this->encrypt_cert_file),
null,
0,
1
);
if ($encrypted) {
@unlink($file);
$body = file_get_contents($encrypted);
@unlink($signed);
@unlink($encrypted);
//The message returned by openssl contains both headers
and body, so need to split them up
$parts = explode("\n\n", $body, 2);
$this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
$body = $parts[1];
} else {
@unlink($file);
@unlink($signed);
@unlink($encrypted);
throw new phpmailerException($this->lang('signing') .
openssl_error_string());
}
} else {
if ($signed) {
@unlink($file);
$body = file_get_contents($signed);
@unlink($signed);
//The message returned by openssl contains both headers
and body, so need to split them up
$parts = explode("\n\n", $body, 2);
$this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
$body = $parts[1];
} else {
@unlink($file);
@unlink($signed);
throw new phpmailerException($this->lang('signing') .
openssl_error_string());
}
}
}
然後尋找:
public function sign($cert_filename, $key_filename, $key_pass,
$extracerts_filename = '')
{
$this->sign_cert_file = $cert_filename;
$this->sign_key_file = $key_filename;
$this->sign_key_pass = $key_pass;
$this->sign_extracerts_file = $extracerts_filename;
}
並改變它:
public function sign($cert_filename, $key_filename, $key_pass,
$extracerts_filename = '', $and_encrypt ='0', $encrypt_cert = '')
{
$this->sign_cert_file = $cert_filename;
$this->sign_key_file = $key_filename;
$this->sign_key_pass = $key_pass;
$this->sign_extracerts_file = $extracerts_filename;
$this->encrypt_file = $and_encrypt;
$this->encrypt_cert_file = $encrypt_cert;
}
尋找:
protected $sign_extracerts_file = '';
,並添加這些行後:
protected $encrypt_cert = '';
protected $and_encrypt = '';
隨着這些變化的PHPMailer你可以發送簽名郵件或簽名和加密的電子郵件。它也適用於附件。
我希望對某人有幫助。
*定期PHP只是不添加一行:
App::import('Vendor','PHPMailer/PHPMailerAutoload');
相關問題
- 1. 使用Open SSL發送SMIME電子郵件,電子郵件正文不顯示
- 2. 用PHP郵件發送電子郵件()
- 3. PHP發送電子郵件多次發送電子郵件
- 4. 如何使用PHP發送和接收加密電子郵件
- 5. PHP發送電子郵件
- 6. PHP發送電子郵件
- 7. PHP發送電子郵件
- 8. 閱讀SMIME加密電子郵件的正文
- 9. PHP郵件不發送電子郵件
- 10. 發送電子郵件使用PHP的電子郵件發送給多人
- 11. 在asp.net發送電子郵件發送密碼而不是電子郵件
- 12. PHP發送電子郵件與文件附件 - 電子郵件不發送
- 13. 無法用PHP發送電子郵件
- 14. 用php發送電子郵件
- 15. 用php發送電子郵件
- 16. 不能用PHP發送電子郵件
- 17. 用PHP發送電子郵件失敗
- 18. 使用PHP發送電子郵件
- 19. 無法用PHP發送電子郵件
- 20. 使用PHP發送HTML電子郵件
- 21. 使用php發送電子郵件
- 22. php用圖像發送電子郵件
- 23. 用php發送電子郵件
- 24. 如何用PHP發送電子郵件
- 25. 使用PHP發送電子郵件
- 26. 調試:用PHP發送電子郵件
- 27. 用onclick發送電子郵件php
- 28. 發送忘記密碼電子郵件
- 29. 通過電子郵件發送密碼
- 30. 發送用戶密碼到他的電子郵件...使用php
是其可能 –
您可以檢查此插件的CakePHP 2 https://github.com/LubosRemplik/CakePHP-Encrypt-Plugin – tarikul05
謝謝,但這隻適用於pgp。 – rimba