Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello,
I want to put an extra measure of security to a form by encrypting the emails going out of the server. I already tested this with my own server at home and it works properly. If you want to see the sample form I created you can go to http://ricardocrane.no-ip.info/private_mail.php. The message will be sent encrypted to my email address.
I will like to implement this functionality to a different form that has multiple fields that need to be encrypted, not just one field.
Here I'm pasting the code that is processing the private_mail.php form.
As you can see, the fwrite($fp, $body); is writing the contents of the body field of the message to the file that will be encrypted.
I have a form that has multiple fields. I want to find out how to encrypt multiple fields.
This is the code that is processing the form:
==========================Code: Select all
<?php
// create short variable names
$from = $_POST['from'];
$title = $_POST['title'];
$body = $_POST['body'];
$to_email = 'pablo@myemailaddress.com';
// Tell gpg where to find the key ring
// On this system, user nobody's home directory is /tmp/
putenv('GNUPGHOME=/home/www/.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 -a --recipient 'Pablo <pablo@myemailaddress.com>' --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 encrypted file
$contents = fread ($fp, filesize ($outfile)) ;
// delete the encrypted temp file
unlink($outfile);
mail($to_email, $title, $contents, "From: $from");
echo '<h1>Message Sent</h1>
<p>Your message was encrypted and sent.
<p>thank you.';
}
}
if($result!=0)
{
echo '<h1>Error:</h1>
<p>Your mesage could not be encrypted, so has not been sent.
<p>Sorry.';
}
?>feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]