Working example:
<?php
$data = <<< EOF
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
You have my authorization to spend 10,000 on dinner expenses.
The CEO
EOF;
$fp = fopen("msg.txt", "w");
fwrite($fp, $data);
fclose($fp);
$headers = array("From" => "[email protected]");
openssl_pkcs7_sign("msg.txt", "signed.txt", "file://email.pem", array("file://email.pem", "123456"), $headers);
$data = file_get_contents("signed.txt");
$parts = explode("\n\n", $data, 2);
mail("[email protected]", "Signed message.", $parts[1], $parts[0]);
echo "Email sent";
?>