pantz.org banner
Send an PGP encrypted e-mail with PHP
Posted on 11-03-2002 02:13:00 UTC | Updated on 11-03-2002 02:13:00 UTC
Section: /software/php/ | Permanent Link

This is some PHP code that uses GNUPG to send an encrypted email to someone. Like having a user type a message in a message box on a webpage and have have that message sent to a person over email. The person recieving the e-mail would be able to decrypt the email because the form on the server used that persons public PGP key. Make sure the browser session connection is SSL encrypted (https) for the most security.

<? 

$testemail = "[email protected]";
$emailsubject = "Encrypted Information";
$emailfrom = "From: [email protected];
$body = "-== Information to be Encrypted ==-\n\n";

//Tell gnupg where the key ring is. Home dir of user web server is running as.
putenv("GNUPGHOME=/var/www/.gnupg");

//create a unique file name
$infile = tempnam("/tmp", "PGP.asc");
$outfile = $infile.".asc";

//write form variables to email
$fp = fopen($infile, "w");
fwrite($fp, $body);
fclose($fp);

//set up the gnupg command. Note: Remember to put E-mail address on the gpg keyring.
$command = "/usr/bin/gpg -a --recipient 'Mini Me <[email protected]>' \\
--encrypt -o $outfile $infile";

//execute the gnupg 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 file
	unlink($outfile);


	//send the email
	mail ($testemail, $emailsubject, $contents, $emailfrom);

	print "<html>Thank you for your information. Your encrypted E-Mail has been sent.</html>";

     } 


}

if($result!=0) {
     print "<html>Their was a problem processing the informaion. Please contact <a href=\"mailto:[email protected]\">[email protected]</a>.";
}

?>

Reddit!

Related stories


RSS Feed RSS feed logo

About


3com

3ware

alsa

alsactl

alsamixer

amd

android

apache

areca

arm

ati

auditd

awk

badblocks

bash

bind

bios

bonnie

cable

carp

cat5

cdrom

cellphone

centos

chart

chrome

chromebook

cifs

cisco

cloudera

comcast

commands

comodo

compiz-fusion

corsair

cpufreq

cpufrequtils

cpuspeed

cron

crontab

crossover

cu

cups

cvs

database

dbus

dd

dd_rescue

ddclient

debian

decimal

dhclient

dhcp

diagnostic

diskexplorer

disks

dkim

dns

dos

dovecot

drac

dsniff

dvdauthor

e-mail

echo

editor

emerald

encryption

ethernet

expect

ext3

ext4

fat32

fedora

fetchmail

fiber

filesystems

firefox

firewall

flac

flexlm

floppy

flowtools

fonts

format

freebsd

ftp

gdm

gmail

gnome

google

gpg

greasemonkey

greylisting

growisofs

grub

hacking

hadoop

harddrive

hba

hex

hfsc

html

html5

http

https

hulu

idl

ie

ilo

intel

ios

iperf

ipmi

iptables

ipv6

irix

javascript

kde

kernel

kickstart

kmail

kprinter

krecord

kubuntu

kvm

lame

ldap

linux

logfile

lp

lpq

lpr

maradns

matlab

memory

mencoder

mhdd

mkinitrd

mkisofs

moinmoin

motherboard

mouse

movemail

mplayer

multitail

mutt

myodbc

mysql

mythtv

nagios

nameserver

netflix

netflow

nginx

nic

ntfs

ntp

nvidia

odbc

openbsd

openntpd

openoffice

openssh

openssl

openvpn

opteron

parted

partimage

patch

perl

pf

pfflowd

pfsync

photorec

php

pop3

pop3s

ports

postfix

power

procmail

proftpd

proxy

pulseaudio

putty

pxe

python

qemu

r-studio

raid

recovery

redhat

router

rpc

rsync

ruby

saltstack

samba

schedule

screen

scsi

seagate

seatools

sed

sendmail

sgi

shell

siw

smtp

snort

solaris

soundcard

sox

spam

spamd

spf

spotify

sql

sqlite

squid

srs

ssh

ssh.com

ssl

su

subnet

subversion

sudo

sun

supermicro

switches

symbols

syslinux

syslog

systemd

systemrescuecd

t1

tcpip

tcpwrappers

telnet

terminal

testdisk

tftp

thttpd

thunderbird

timezone

ting

tls

tools

tr

trac

tuning

tunnel

ubuntu

unbound

vi

vpn

wget

wiki

windows

windowsxp

wireless

wpa_supplicant

x

xauth

xfree86

xfs

xinearama

xmms

youtube

zdump

zeromq

zic

zlib