How to send digital signed email using Pear mail
Is there any way how to send digital signed email with pear Mail?
I thied this code, but it hasnt run.
<?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";
?>
Can somebody give me advice how to solve this issue? Thanks.
** I found on internet solution, where man can genarate signed email in file with openssl_pkcs7_sign function. I have generated this file, but I dont know how parse this file for $mail_object->send function args. Expecially I dont know how to construct headers array
File content :
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 signe开发者_运维问答d 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--
Thanks for help
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);
I think you should try:
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);
and sending the header params:
$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]);
精彩评论