This is some PHP code that uses GNUPG to send an encrypted email to someone. Like having a user type a message in a message box on a webpage and have have that message sent to a person over email. The person recieving the e-mail would be able to decrypt the email because the form on the server used that persons public PGP key. Make sure the browser session connection is SSL encrypted (https) for the most security.
<? $testemail = "[email protected]"; $emailsubject = "Encrypted Information"; $emailfrom = "From: [email protected]; $body = "-== Information to be Encrypted ==-\n\n"; //Tell gnupg where the key ring is. Home dir of user web server is running as. putenv("GNUPGHOME=/var/www/.gnupg"); //create a unique file name $infile = tempnam("/tmp", "PGP.asc"); $outfile = $infile.".asc"; //write form variables to email $fp = fopen($infile, "w"); fwrite($fp, $body); fclose($fp); //set up the gnupg command. Note: Remember to put E-mail address on the gpg keyring. $command = "/usr/bin/gpg -a --recipient 'Mini Me <[email protected]>' \\ --encrypt -o $outfile $infile"; //execute the gnupg command system($command, $result); //delete the unencrypted temp file unlink($infile); if ($result==0) { $fp = fopen($outfile, "r"); if(!$fp||filesize ($outfile)==0) { $result = -1; } else { //read the encrypted file $contents = fread ($fp, filesize ($outfile)); //delete the encrypted file unlink($outfile); //send the email mail ($testemail, $emailsubject, $contents, $emailfrom); print "<html>Thank you for your information. Your encrypted E-Mail has been sent.</html>"; } } if($result!=0) { print "<html>Their was a problem processing the informaion. Please contact <a href=\"mailto:[email protected]\">[email protected]</a>."; } ?>