|
<? Php
// Create short variable names
$ From = $ _ post ['from'];
$ Title = $ _ post ['title'];
$ Body = $ _ post ['body'];
$ To_email = 'Luke @ localhost ';
// Tell gpg where to find the key ring
// On this system, user nobody's home directory is/tmp/
Putenv ('gnupghome =/tmp/. Gnupg ');
// Create a unique file name
$ Infile = tempnam ('', 'pgp ');
$ Outfile = $ infile. '. asc ';
// Write the user's text to the file
$ Fp = fopen ($ infile, 'w ');
Fwrite ($ fp, $ body );
Fclose ($ fp );
// Set up our command
$ Command = "/usr/local/bin/gpg-\
-- Recipient 'Luke welling <luke@tangledweb.com.au> '\
-- Encrypt-o $ outfile $ infile ";
// Execute our gpg 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 temp file
Unlink ($ outfile );
Mail ($ to_email, $ title, $ contents, "from: $ from ");
Echo '<P> your message was encrypted and sent.
<P> thank you .';
}
}
If ($ result! = 0)
{
Echo '<P> your message cocould not be encrypted, so has not been sent.
<P> sorry .';
}
|