note 84546 added to function.openssl-pkcs7-encrypt
| From: | koen dot thomeer at pubmed dot be | Date: | Fri, 18 Jul 2008 11:54:24 +0000 |
| Subject: | note 84546 added to function.openssl-pkcs7-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141654@lists.php.net to get a copy of this message | ||
In the previous example, instead of making your own headers in the encrypted message,
openssl_pkcs7_encrypt() can do it for you with the PKCS7_TEXT flag.
body.txt is the file with the mail body.
publickey.cer is the file with the public certificate.
<?php
// Setup mail headers.
$headers = array("From" => "from@mail.com", "To" =>
"to@mail.com", "Subject" => "Encrypted mail readable with most
clients", "X-Mailer" => "PHP/".phpversion());
// Get the public key certificate.
$pubkey = file_get_contents("publickey.cer");
// Remove some double headers for mail()
$headers_msg = $headers;
unset($headers_msg['To'], $headers_msg['Subject']);
// Encrypt message
openssl_pkcs7_encrypt("body.txt", "enc.txt",$pubkey,$headers_msg,PKCS7_TEXT,1);
// Seperate headers and body for mail()
$data = file_get_contents("enc.txt");
$parts = explode("\n\n", $data, 2);
// Send mail
mail($headers['To'], $headers['Subject'], $parts[1], $parts[0]);
// Remove encrypted message (not fot debugging)
unlink("enc.txt");
?>
----
Server IP: 195.207.10.20
Probable Submitter: 88.197.178.80
----
Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-encrypt.php
Edit -- https://master.php.net/note/edit/84546
Del: integrated -- https://master.php.net/note/delete/84546/integrated
Del: useless -- https://master.php.net/note/delete/84546/useless
Del: bad code -- https://master.php.net/note/delete/84546/bad+code
Del: spam -- https://master.php.net/note/delete/84546/spam
Del: non-english -- https://master.php.net/note/delete/84546/non-english
Del: in docs -- https://master.php.net/note/delete/84546/in+docs
Del: other reasons-- https://master.php.net/note/delete/84546
Reject -- https://master.php.net/note/reject/84546
Search -- https://master.php.net/manage/user-notes.php