This command doesn't work correctly on WIN32 with IIS. Mails aren?t interpreted correctly by IIS SMTP Server (and by Outlook too). The reason is that UNIX and WINDOWS interpret the ?enter to the next line? ascii code in a different way.
Below I present an improved code:
<?php
$data = <<<EOD
Testing 123
This is a test
Test
EOD;
//save the message to a file
$fp = fopen("msg.txt","w");
fwrite($fp,$data);
fclose($fp);
//sign the message using the sender's keys
openssl_pkcs7_sign("msg.txt", "signed.eml", "file://c:/max/cert.pem",
array("file://c:/max/priv.pem","your_password"),
array("To" => "recipient <[email protected]>",
"From" => "sender <[email protected]>",
"Subject" => "Order Notification - Test"),PKCS7_DETACHED,"c:\max\extra_cert.pem");
$file_arry = file("signed.eml");
$file = join ("", $file_arry);
$message = preg_replace("/\r\n|\r|\n/", "\r\n", $file);
$fp = fopen("c:\Inetpub\mailroot\Pickup\signed.eml", "wb");
flock($fp, 2);
fputs($fp, $message);
flock($fp, 3);
fclose($fp);
?>
Besides, if you want to use the keys created with Windows, you should export them (from IE) to the form of PKCS#12 file (*.pfx).
Install OpenSSLWin32 from
http://www.shininglightpro.com/search.php?searchname=Win32+OpenSSL
execute: openssl.exe
enter the commands:
pkcs12 -in <pfx-file> -nokeys -out <pem-certs-file>
pkcs12 -in <pfx-file> -nocerts -nodes -out <pem-key-file>
Next export from IE Root CA certificate as Base-64 *.cer and rename the file to *.pem
And that's all!