I am on a shared server and have a script that I am trying to make encrypt data and send me an encrypted e-mail.
Code: Select all
<?php
//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 GNUPGHOME
putenv("GNUPGHOME=/home/friendsh/.gnupg");
//create vars to hold paths and filenames
$plainTxt = "/home/friendsh/public_html/dev/uncoded.txt";
$crypted = "/home/friendsh/public_html/dev/coded.txt";
//open file and dump in plaintext contents
$fp = fopen($plainTxt, "w+");
fputs($fp, $msg);
fclose($fp);
//invoke GNUPG to encrypt file contents
system("/usr/bin/gpg --encrypt -ao $crypted -r 'Keith Moon <keith@oops.co.uk>' $plainTxt");
//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 = "keith@oops.co.uk";
$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>
";
?>By reomving the unlink I can view the files contents. I find that the uncoded.txt file contains the correct data but the coded.txt file is always empty.
I am a beginner on this so any help or ideas on getting the encryption to take place (simply expressed) would be great.
I think I may have a problem here -
putenv("GNUPGHOME=/home/friendsh/.gnupg");
Regards
Keith