Help! This is really starting to get to me. I've got my PGP Key ring set up and can encrypt via Telnet using the following command:
pgpe -r 'phrplc <keys@phrplc.com>' $plainTxt -o $crypted
But I'm trying to encrypt an email within PHP. I've got the following script but the command line part just doesn't want to work. I'm sure I've got PGPPATH correct at the top and permissions on the directory are fine to write (it works fine up to the command line part). I've not run command line stuff within PHP before - Am I doing something obviously wrong? Any help much appreciated!
<?php
$sender_name = "PHR Website";
$sender_email = "data@phrplc.com";
$secret_msg = "This is a test message";
//build the message string
$msg = "Sender's Full Name:\t$sender_name\n";
$msg .= "Sender's E-Mail:\t$sender_email\n";
$msg .= "Secret Message?\t$secret_msg\n\n";
//set the environment variable for PGPPATH
putenv("PGPPATH=/usr/local/bin/pgp");
//generate token for unique filenames
$tmpToken = md5(uniqid(rand()));
//create vars to hold paths and filenames
$plainTxt = "/home/phrplc/phrplc-www/test2/" . "$tmpToken" . "data";
$crypted = "/home/phrplc/phrplc-www/test2/" . "$tmpToken" . "pgpdata";
//open file and dump in plaintext contents
$fp = fopen($plainTxt, "w+");
fputs($fp, $msg);
fclose($fp);
//invoke PGP to encrypt file contents
system("/usr/local/bin/pgp/pgpe -r 'phrplc <keys@phrplc.com>' $plainTxt -o $crypted") or die ("eh"); // works on command line
//open file and read encrypted contents into var
$fd = fopen($crypted, "r");
$mail_cont = fread($fd, filesize($crypted));
fclose($fd);
//delete files!
unlink($plainTxt);
unlink($crypted);
// Build mail message and send it to target recipient.
$recipient = "andyt@theandies.com";
$subject = "Secret Message";
$mailheaders = "From: My Web Site\n";
$mailheaders .= "Reply-To: $sender_email\n\n";
mail("$recipient", "$subject", $mail_cont, $mailheaders);
// Print confirmation to screen.
echo "
<H1 align=center>Thank You, $sender_name</h1>
<p align=center>Your secret message has been sent.</p>
";
?>