<html><body>
<small><pre>
example use of gpg_encrypt()
(c) Atom Emet, 14 Jan 2004
(c) Atom Emet, 17 Feb 2006
distributed under GPL
other licenses available on request
<a href="http://www.gnu.org/copyleft/gpl.html"
>http://www.gnu.org/copyleft/gpl.html</a>

more info about gpg_encrypt() here:
<a href="http://Business-PHP.com/opensource/gpg_encrypt/"
>http://Business-PHP.com/opensource/gpg_encrypt/</a>
</small></pre>
<form action="<?php
	// display a form that will
	// submit to itself
	echo($_SERVER[REQUEST_URI]);
?>" method="post">
<textarea name="message" cols="30" rows="6"><?php
	// the message will be displayed in the form
	//
	// note: "magic_quotes_gpc" will be
	// essentially the same as using
	// addslashes() - this will affect
	// the text being POSTed.
	// you may wish to use stripslashes()
	// before sending your data to GnuPG.
	echo($_POST[message]);
?></textarea>
<br>
<input type="submit" value="Encrypt and send your message">
<hr>
<?php
////////////////////////////
// everything from here down
// only happens if a message was
// submitted and something needs
// to be done with it.
if(!empty($_POST[message])) {
   $message = $_POST[message];

   // require 'gpg_encrypt.php' to create
   // the gpg_encrypt() function
   require_once('gpg_encrypt.php');

   // encrypt $message to key ID 0x123456
   // using /usr/local/bin/gpg
   // and a keyring at /home/www/.gnupg
   $gpg = gpg_encrypt("${message}", '/usr/local/bin/gpg' , '/home/www/.gnupg', '0x123456');
   // $gpg is an array containing
   // $gpg[0] encrypted output (STDOUT)
   // $gpg[1] warnings and notices (STDERR)
   // $gpg[2] exit status from gpg

   // test gpg's exit status
   if("$gpg[2]" == '0') {
      // if the gpg command returned zero
      // then mail out the message
      // to "email@address.com"
      // with a subject: encrypted message
      mail("email@address.com", 'encrypted message', "$gpg[0]");
      echo('Your message was encrypted and sent');
   } else {
      // if the gpg command returned non-zero
      // then display gpg's diagnostic output
      echo("<pre>\n$gpg[1]</pre>");
   }
}
?>
</body>
</html>
