有没有办法如何使用pear Mail发送数字签名电子邮件?
我骗了这段代码,但它没有运行。
<?php
require_once("Mail.php");
require_once('Mail\mime.php');
$recipients = "petr.kostroun@xxx.cz";
$headers["From"] = "mailer@xxx.cz";
$headers["To"] = $recipients;
$headers["Subject"] = "Zkouska";
$params["host"] = "mail.xxx.cz";
$params["username"] = "server@xxx.cz";
$params["password"] = "xxx";
$body = "Zkouska Spojeni !";
$mime = new Mail_mime();
$fp = fopen("./msg.txt", "w");
fwrite($fp, $body );
fclose($fp);
echo "Sending mail:\n";
echo "Headers:\n" . print_r($headers);
echo "\n\nBody:\n$body";
echo "\n---END OF MAIL BODY---\n";
openssl_pkcs7_sign("C:/data/www/msg.txt", "C:/data/www/signed.txt", "file://C:/data/www/04.pem", "file://C:/data/www/newkey.pem", $headers);
$data = file_get_contents("C:/data/www/signed.txt");
$mime->setTXTBody($data);
$body = $mime->get();
$headers = $mime->headers($headers);
$headers["Content-Type"] = "Multipart/signed; protocol=\"application/pkcs7-signature\"; micalg=sha1; boundary=\"------------ms070206070302000302000502\"";
$mail_object =& Mail::factory("smtp", $params);
$mail_object->send($recipients, $headers, $body);
echo "Email sent";
?>
有人可以给我建议如何解决这个问题吗?感谢。
** 我发现在互联网解决方案中,人们可以使用openssl_pkcs7_sign函数在文件中标记已签名的电子邮件。我已生成此文件,但我不知道如何为$ mail_object-&gt; send function args解析此文件。特别是我不知道如何构造头数组
文件内容:
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
From: info@xxx.cz
To: petr.kostroun@xxx.cz, vysledky@xxx.cz
Subject: Zkouska
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boundary="----E3E6271C75DBBBCB30B457C24A97B23B"
This is an S/MIME signed message
------E3E6271C75DBBBCB30B457C24A97B23B
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
From: info@xxx.cz
To: petr.kostroun@xxx.cz, vysledky@xxx.cz
Subject: Zkouska
#Zkusebni podepsanej email, neodpovidejte prosim
------E3E6271C75DBBBCB30B457C24A97B23B
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
MIIE9wYJKoZIhvcNAQcCoIIE6DCCBOQCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3
DQEHAaCCApswggKXMIICAAIBBDANBgkqhkiG9w0BAQQFADCBnDELMAkGA1UEBhMC
Q1oxFzAVBgNVBAgMDkN6ZWNoIFJlcHVibGljMQ8wDQYDVQQHDAZQcmFndWUxDzAN
BgNVBAoMBkRhbnRlbTERMA8GA1UECwwIRW1wbG95ZWUxFzAVBgNVBAMMDkRhbnRl
bSBDQSBhdXRoMSYwJAYJKoZIhvcNAQkBFhdwZXRyLmtvc3Ryb3VuQGRhbnRlbS5j
ejAeFw0xMTA5MDgxMDQyNDJaFw0yMTA3MTcxMDQyNDJaMIGKMQswCQYDVQQGEwJD
WjEXMBUGA1UECBMOQ3plY2ggUmVwdWJsaWMxDzANBgNVBAoTBkRhbnRlbTERMA8G
A1UECxMIRW1wbG95ZWUxFjAUBgNVBAMTDVBldHIgS29zdHJvdW4xJjAkBgkqhkiG
9w0BCQEWF3BldHIua29zdHJvdW5AZGFudGVtLmN6MIGfMA0GCSqGSIb3DQEBAQUA
A4GNADCBiQKBgQCwxNLJPu46NOuGVuQSNtoOUZjN6QYoxSgpOhFtn6Ld/5MaJAaX
SLg3jm2F7NKXvazdma0MZnWiKoomekx77bHSHqSriq5PrO0FxR2V81jGpVKd2jS2
XoMEgiz2bGuy6xWIrdl/ocmMvrusRbL1N/prJGcQCI7TvLlWZr3+otauZwIDAQAB
MA0GCSqGSIb3DQEBBAUAA4GBAJS0U/u8RHlzxVId86lXF1IHdJlmUfqM5uJ0zrjE
a6g1C/7pExSpM9s7RqDkDdgHk2Ok3bl2XBmDvWNWJSsNxc9Gy77gT4qwm93og03p
FDn3ikBIhP+LddDwvre28/eVu/59R6QGMe2VEGNREWvdPHbV7KD1GPim9AL4il3j
VMtHMYICJDCCAiACAQEwgaIwgZwxCzAJBgNVBAYTAkNaMRcwFQYDVQQIDA5DemVj
aCBSZXB1YmxpYzEPMA0GA1UEBwwGUHJhZ3VlMQ8wDQYDVQQKDAZEYW50ZW0xETAP
BgNVBAsMCEVtcGxveWVlMRcwFQYDVQQDDA5EYW50ZW0gQ0EgYXV0aDEmMCQGCSqG
SIb3DQEJARYXcGV0ci5rb3N0cm91bkBkYW50ZW0uY3oCAQQwCQYFKw4DAhoFAKCB
2DAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xMTA5
MDgxNjE5MzJaMCMGCSqGSIb3DQEJBDEWBBTW5eHrz1I9fM/YTcek/1RBvTrPqzB5
BgkqhkiG9w0BCQ8xbDBqMAsGCWCGSAFlAwQBKjALBglghkgBZQMEARYwCwYJYIZI
AWUDBAECMAoGCCqGSIb3DQMHMA4GCCqGSIb3DQMCAgIAgDANBggqhkiG9w0DAgIB
QDAHBgUrDgMCBzANBggqhkiG9w0DAgIBKDANBgkqhkiG9w0BAQEFAASBgIUpL8bB
w4UpFJEdUO2f0aIc0nm7XnEtVUPkBhhfAfikSJLjNraLmlwQq0f7R/EHdeUzutvW
nuY8A5NtqNF/Efyy8g19GEXCDgxYMgSiUn8AEhhdUvs7Qe45B3ONgLdYfmnF8yX/
w/ZrUGzcmG46dsH/HPapYFmscmbbm5G1GWdU
------E3E6271C75DBBBCB30B457C24A97B23B--
感谢您的帮助
答案 0 :(得分:2)
openssl_pkcs7_sign(“C:/data/www/msg.txt”,“C:/data/www/signed.txt”, “file:// C:/data/www/04.pem”,“file:// C:/data/www/newkey.pem”, $头);
我认为你应该尝试:
openssl_pkcs7_sign("C:/data/www/msg.txt",
"C:/data/www/signed.txt",
"file://C:/data/www/04.pem",
array("file://C:/data/www/newkey.pem","CRT pass"),
$headers);
并发送标题参数:
$data = file_get_contents("C:/data/www/signed.txt");
$parts = explode("\n\n", $data, 2);
// with mail() function you should
mail($to, $subject, $parts[1], $parts[0]);
// I suppose in the same way for Pear Mail
$mail_object =& Mail::factory("smtp", $params);
$mail_object->send($recipients, $parts[0], $parts[1]);