saadi06 2 Junior Poster in Training

I have one certificate in the pfx format and I am trying to sign s/mime email with it using openssl but I am getting this error. Warning: openssl_pkcs7_sign(): error getting private key. Here is my code that I am trying to sign the file

$privkey = 'file://'.realpath('email.pfx');
openssl_pkcs7_sign("msg.txt", "signed.txt", $signcert,array($privkey, $password),$headers ,PKCS7_DETACHED );

My question is how can I sign the file using pfx certificate or I have to convert the certificate first into privatekey.pem format.
Thanks in advance.