<"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text / html; charset = gb2312" />
<title> php mail function to send e-mail (can be attached) </ title>
</ head>
<body>
<? php
// you might need to change this line, if you do not use
// the default ports, 80 for normal traffic and 443 for ssl
if ($ _ server ['server_port']! = 443)
echo '<p> <font color = red>
warning: you have not connected to this page using ssl.
your message could be read by others. </ font> </ p> ';
?>
<form method = post action = "send_private_mail.php"> <br>
your email address: <br>
<input type = text name = from size = 38> <br>
subject: <br>
<input type = text name = title size = 38> <br>
your message: <br>
<textarea name = body cols = 30 rows = 10>
</ textarea> <br>
<input type = submit value = "send!">
</ form>
</ body>
</ html>
send_private_mail.php file
<? 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 -a
--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: $ fromn");
echo '<h1> message sent </ h1>
<p> your message was encrypted and sent.
<p> thank you. ';
}
}
if ($ result! = 0)
{
echo '<h1> error: </ h1>
<p> your message could not be encrypted, so has not been sent.
<p> sorry. ';
}
/ *
This is a function using php mail sent mail, but also support the sending of attachments Oh.
* /
?>)