pantz.org banner
A form that sends an 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 page contains 3 pages of info broken up into 3 boxes below. The first section you fill out the form. The second section you check what you filled out. On the third section the email gets sent. The javascript checks that certian boxes are filled out. The PHP code will update the form fields if you go back and forth from the check page and the entry page. Put these three different sections below in three different files. The php code is very simple and not very good but it works.

Page 1

<?
// Initialize session
session_start();

?>

<html>

<script language="JavaScript">
<!--

function checkFields() {

if (document.metsign.billtoccname.value == 0)
       {
          alert("Please provide us with the name that appears on the Credit Card.\n"); 
          return false;
       }
if (document.metsign.billtoaddress1.value == 0)
       {
          alert("Please provide us with the billing address of the Credit Card.\n");    
          return false;
       }
if (document.metsign.billtocity.value == 0)
       {
          alert("Please provide us with your city.\n");
          return false;
       }
if (document.metsign.billtostate.value == 'select_state')
       {
          alert("Please provide us with your state.\n");
          return false;
       }
if (document.metsign.billtozip.value == 0)
       {
          alert("Please provide us with your zip.\n");
          return false;
       }
if (document.metsign.billtophone.value == 0)
       {
          alert("Please provide us with your phone number.\n");
          return false;
       }

if (!document.metsign.cctype[0].checked && !document.metsign.cctype[1].checked && !document.metsign.cctype[2].checked)
	 {
	  alert("Please choose a Credit Card type.\n");
	  return false;
         }

if (document.metsign.ccnumber.value == 0)
       {
          alert("Please provide us with your credit card number.\n");
          return false;
       }

if (document.metsign.ccexpmonth.value == 'select_month')
       {
          alert("Please provide us with your Credit Cards expiration month.\n");
          return false;
       }
if (document.metsign.ccexpyear.value == 'select_year') 
       {
          alert("Please provide us with your Credit Cards expration year\n");
          return false;
       }
if (document.metsign.billtosubscription.value == 'select_sub')
       {
          alert("Please provide us with your subscription type.\n");
          return false;
       }

}

// -->

</script>

<form action="formpg2.php" method="POST" name="metsign">

Please provide us with the credit card information below.<br><br>

<b>User-Info:</b><br><br>

First Name<input type="text" name="userfirstname" size="29" maxlength="29"<? if (session_is_registered("userfirstname") == true) { print "value =\"$userfirstname\""; 
} else { print "value=\"\""; } ?>><br><br>
Last Name<input type="text" name="userlastname" size="29" maxlength="29"<? if (session_is_registered("userlastname") == true) { print "value =\"$userlastname\""; } 
else { print "value=\"\""; } ?>><br><br>

<b>Bill-To:</b><br><br>

Company Name<input type="text" name="billtocompanyname" size="29" maxlength="29"<? if (session_is_registered("billtocompanyname") == true) { print "value 
=\"$billtocompanyname\""; } else { print "value=\"\""; } ?>><br><br>

Name on Credit Card<input type="text" name="billtoccname" size="29" maxlength="29"<? if (session_is_registered("billtoccname") == true) { print "value =\"$firstname 
$billtoccname\""; } else { print "value=\"\""; } ?>><br><br>

Address 1<input type="text" name="billtoaddress1" size="29" maxlength="29"<? if (session_is_registered("billtoaddress1") == true) { print "value 
=\"$billtoaddress1\""; } else { print "value=\"\""; } ?>><br><br>

Address 2<input type="text" name="billtoaddress2" size="29" maxlength="29"<? if (session_is_registered("billtoaddress2") == true) { print "value 
=\"$billtoaddress2\""; } else { print "value=\"\""; } ?>><br><br> 

City<input type="text" name="billtocity" size="29" maxlength="29"<? if (session_is_registered("billtocity") == true) { print "value =\"$billtocity\""; } else { print 
"value=\"\""; } ?>><br><br> 

State<SELECT NAME="billtostate">
<OPTION selected value="select_state">Select</option>

<option value="AK">AK</option>
<option value="AL">AL</option>
<option value="AR">AR</option>
<option value="AZ">AZ</option>
<option value="CA">CA</option>

<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DC">DC</option>
<option value="DE">DE</option>
<option value="FL">FL</option>

<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="IA">IA</option>
<option value="ID">ID</option>
<option value="IL">IL</option>

<option value="IN">IN</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="MA">MA</option>

<option value="MD">MD</option>
<option value="ME">ME</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MO">MO</option>

<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="NE">NE</option>

<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NV">NV</option>
<option value="NY">NY</option>

<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>

<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>

<option value="VA">VA</option>
<option value="VT">VT</option>
<option value="WA">WA</option>
<option value="WI">WI</option>
<option value="WV">WV</option>

<option value="WY">WY</option>
</select><br><br>

Zip Code<input type="text" name="billtozip" size="10" maxlength="12"<? if (session_is_registered("billtozip") == true) { print "value =\"$billtozip\""; } else { 
print "value=\"\""; } ?>><br><br> 

Phone Number<input type="text" name="billtophone" size="15" maxlength="15"<? if (session_is_registered("billtophone") == true) { print "value =\"$billtophone\""; } 
else { print "value=\"\""; } ?>><br><br>


Type of credit card<br><br>

Visa<input type="radio" name="cctype" value="Visa"><br>

Mastercard<input type="radio" name="cctype" value="Mastercard"><br>

Discover<input type="radio" name="cctype" value="Discover"><br><br>

Credit Card Number<input type="text" name="ccnumber" size="16" maxlength="16"<? if (session_is_registered("ccnumber") == true) { print "value =\"$ccnumber\""; } else 
{ print "value=\"\""; } ?>><br><br>

Credit Card Expiration <select name="ccexpmonth">
<OPTION selected value="select_month">Select Month</option>

<OPTION value="1">1</option>
<OPTION value="2">2</option>
<OPTION value="3">3</option>
<OPTION value="4">4</option>
<OPTION value="5">5</option>

<OPTION value="6">6</option>
<OPTION value="7">7</option>
<OPTION value="8">8</option>
<OPTION value="9">9</option>
<OPTION value="10">10</option>

<OPTION value="11">11</option>
<OPTION value="12">12</option>
</select>

<select name="ccexpyear">
<OPTION selected value="select_year">Select Year</option>

<OPTION value="2001">2001</option>
<OPTION value="2002">2002</option>
<OPTION value="2003">2003</option>
<OPTION value="2004">2004</option>
<OPTION value="2005">2005</option>

<OPTION value="2006">2006</option>
<OPTION value="2007">2007</option>
<OPTION value="2008">2008</option>
<OPTION value="2009">2009</option>
<OPTION value="2010">2010</option>

<OPTION value="2011">2011</option>
<OPTION value="2012">2012</option>
</select><br><br>

<select name="billtosubscription">
<OPTION selected value="select_sub">Select Subscription</option>

<OPTION value="Q1">Quarterly Subscription</option>
<OPTION value="Y1">Yearly Subscription</option>
</select><br><br>

<center><input type="submit" name="submit" value="Next -->" onClick="return checkFields();"></center> 

</form>
</html>

Page 2

<?
// Initialize session
session_start();

session_register("userfirstname");
$GLOBALS['userfirstname']=$HTTP_POST_VARS['userfirstname'];

session_register("userlastname");
$GLOBALS['userlastname']=$HTTP_POST_VARS['userlastname'];

session_register("billtocompanyname");
$GLOBALS['billtocompanyname']=$HTTP_POST_VARS['billtocompanyname'];

session_register("billtoccname");
$GLOBALS['billtoccname']=$HTTP_POST_VARS['billtoccname'];

session_register("billtoaddress1");
$GLOBALS['billtoaddress1']=$HTTP_POST_VARS['billtoaddress1'];

session_register("billtoaddress2");
$GLOBALS['billtoaddress2']=$HTTP_POST_VARS['billtoaddress2'];

session_register("billtocity");
$GLOBALS['billtocity']=$HTTP_POST_VARS['billtocity'];

session_register("billtostate");
$GLOBALS['billtostate']=$HTTP_POST_VARS['billtostate'];

session_register("billtozip");
$GLOBALS['billtozip']=$HTTP_POST_VARS['billtozip'];

session_register("billtophone");
$GLOBALS['billtophone']=$HTTP_POST_VARS['billtophone'];

session_register("cctype");
$GLOBALS['cctype']=$HTTP_POST_VARS['cctype'];

session_register("ccnumber");
$GLOBALS['ccnumber']=$HTTP_POST_VARS['ccnumber'];

session_register("ccexpmonth");
$GLOBALS['ccexpmonth']=$HTTP_POST_VARS['ccexpmonth'];

session_register("ccexpyear");
$GLOBALS['ccexpyear']=$HTTP_POST_VARS['ccexpyear'];

session_register("billtosubscription");
$GLOBALS['billtosubscription']=$HTTP_POST_VARS['billtosubscription'];


?>

<html><center><h3>After you have verfied this information is correct please click the finish button.</h3></center><br>
<center><h3>If you need to make changes click the back button on your browser</h3></center><br>

<?
print "<center><table border=\"1\">

<tr><td><b>Users First Name:</b> $userfirstname</td></tr>

<tr><td><b>Users Last Name:</b> $userlastname</td></tr>

<tr><td><b>Met Cert #:</b> $metcertnum</td></tr>

<tr><td><b>Company Name:</b> $billtocompanyname</td></tr>

<tr><td><b>Name on Credit Card:</b> $billtoccname</td></tr> <tr><td><b>Address 1:</b> 
$billtoaddress1</td></tr>

<tr><td><b>Address 2:</b> $billtoaddress2</td></tr> <tr><td><b>City:</b> $billtocity</td></tr>

<tr><td><b>State:</b> $billtostate</td></tr> <tr><td><b>Zip:</b> $billtozip</td></tr>

<tr><td><b>Phone Number:</b> $billtophone</td></tr> <tr><td><b>Credit Card Type:</b> 
$cctype</td></tr>

<tr><td><b>Credit Card Number:</b> $ccnumber</td>

<tr><td><b>Credit Card Expration:</b> $ccexpmonth/$ccexpyear</td></tr>

<tr><td><b>Subscription Type:</b> $billtosubscription</td></tr>

</table></center>

<center> <form><input type=\"button\" name=\"Edit Information\" value=\"Finish\" onClick=\"document.location.href='formpg3.php';\">

<html>"

?>

Page 3

<? 
session_start(); // initialize session

// setup email addributes \\
$testemail = "[email protected]";
$emailsubject = "Form Information";
$emailfrom = "From: [email protected]";
$body = "
-=User Info=-\n\n
Name: $firstname $lastname\n

-=Bill-To Info=-\n\n
Bill-To Company Name: $billtocompanyname\n
Bill-To Credit Card Name: $billtoccname\n
Bill-To Address1: $billtoaddress1\n
Bill-To Address2: $billtoaddress2\n
Bill-To City: $billtocity\n
Bill-To State: $billtostate\n
Bill-To Zip: $billtozip\n
Bill-To Phone: $billtophone\n
Bill-To Credit Card Type: $cctype\n
Bill-To Credit Card Number: $ccnumber\n
Bill-To Credit Card Exp: $ccexpmonth/$ccexpyear\n
Bill-To Subscription: $billtosubscription\n
";

//send the email. I suggest if your sending real credit card info you 
//encrypt the e-mail. see www.pantz.org for an example
mail ($testemail, $emailsubject, $body, $emailfrom);

print "<html><center>Thanks for filling out the form.</center></html>";

?>

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