Forums

PHP

This topic is locked

Newbie: E-mail form problem

Posted 01 Feb 2006 10:37:52
1
has voted
01 Feb 2006 10:37:52 Kevin Bedford posted:
Hi all,

New to PHP, i am using a php e-mail form that goes to an e-mail address, the problem is that not all the details show up in the received e-mail.

Instead of the word "Address" I get "Dress", "Name" shows as "Me", "Phone" as "One"

Any suggestions would be appreciated!!!

Thanks

Replies

Replied 07 Feb 2006 18:52:13
07 Feb 2006 18:52:13 B D replied:
can you post the code?

DMX | PHP | SQL
Replied 07 Feb 2006 20:59:05
07 Feb 2006 20:59:05 Kevin Bedford replied:
<?php

####################################################################################
#
# Emailer
#
# - Supports PHP Versions 4.0 upwards.
# - Supports up to 100 posted fields in the format of "01namehere" (2 digit integer
# to signify order, plus name of field.)
# - Supports storing data to a MySQL Database
#
# Requirements
# - PHP with working mail() function, using sendmail or equivalent
#
####################################################################################

# GENERAL OPTIONS #

#
# Set email address to send mail
$toemailaddress = " ";

#
# Set name and address email should come from
# Example - Your website name, Site Support Request, etc

# Custom name toggle - use the persons name/email address, for use with reply button when
# receiving email
# 1 - Use Custom name/email
# 0 - Use Static name/email
$customname = 1;

# Custom name/email settings
# Select the POST field used for email sender name and email sender address
$fromnamefield = "name";
$fromemailfield = "email";

# Static name/email settings
$fromname = "Cruise Te Anau";
$fromemail = " ";

#
# Set email subject
$emailsubject = "Enquiry";

#
# Set URL to send users to on successful email
$gotourl = "Thankyou.html";

#
# Set allowed POST values
# EXAMPLE - $allowed = array("01title", "02name", "03phone", "04fax", "05mobile" , "06email", "07address", "08city", "09comments",);

$allowed = array("name", "email", "phone", "fax", "address", "query",);

######### BASIC EMAILER FORM STOP HERE ###########

# MYSQL DATABASE OPTIONS #

# Note - Database Table must be setup with each allowed POST field in order as its name
# Example:-
# POST Field - "01name"
# Database Column - name
# Columns should be named lower case within the database

#
# Store data in MySQL? (0 or 1)
$mysqlstore = 0;

# Database Details
# $dbhost - Database Server Hostname/IP
# $dbuser - MySQL Username
# $dbpass - MySQL Password
# $dbname - Database Name on MySQL Server
# $dbtable - Table within Database to store data

$dbhost = "localhost";
$dbuser = "user";
$dbpass = "pass";
$dbname = "name";
$dbtable = "table";

####################################################################################
# DO NOT MODIFY BELOW THIS LINE
####################################################################################

function minimum_version($vercheck) {
$minver = explode(".", $vercheck);
$curver = explode(".", phpversion());
if (($curver[0] < $minver[0])
|| (($curver[0] = $minver[0])
&& ($curver[1] < $minver[1]))
|| (($curver[0] = $minver[0])
&& ($curver[1] = $minver[1])
&& ($curver[2][0] < $minver[2][0]))) {
return false;
} else {
return true;
}
}

if (!minimum_version("4.1.0") {
$emailvars = $HTTP_POST_VARS;
} else {
$emailvars = $_POST;
}

$varstosend = array();
ksort($emailvars);
$maxkeylen = 0;
foreach ($emailvars as $name => $value) {
$check = in_array($name, $allowed);
if ($check) {
$name2 = substr($name, 2);
if (strlen($name2) > $maxkeylen) {
$maxkeylen = strlen($name2);
}
$namestart = strtoupper(substr($name2, 0, 1));
$namerest = substr($name2, 1);
$newname = $namestart.$namerest;
$varstosend[$newname] = $value;
}
}
if ($mysqlstore == 1) {
$dbc = mysql_connect($dbhost, $dbuser, $dbpass);
$dbs = mysql_select_db($dbname, $dbc);
foreach ($varstosend as $key => $value) {
$insertcol .= strtolower($key).", ";
$insertcoldata .= "\'".$value."\', ";
}
$insertcol = substr($insertcol, 0, -2);
$insertcoldata = stripslashes(substr($insertcoldata, 0, -2));
$dbinsquery = "INSERT INTO ".$dbtable." (".$insertcol." VALUES (".$insertcoldata."";
$dbins = mysql_query($dbinsquery);
if (!$dbins) {
$error = 1;
$dberror = 1;
$dberrordesc = mysql_error();
}
}
foreach ($varstosend as $key => $val) {
$emailmessage .= $key;
for ($i = strlen($key); $i < $maxkeylen; $i++) {
$emailmessage .= " ";
}
$emailmessage .= " - ".$val."\n";
}
if ($customname == 0) {
$fromemailname = $fromname;
$fromemailaddress = $fromemail;
} elseif ($customname == 1) {
$fromemailname = $emailvars[$fromnamefield];
$fromemailaddress = $emailvars[$fromemailfield];
}
$sendmail = mail($toemailaddress, $emailsubject, $emailmessage, "From: ".$fromemailname." <".$fromemailaddress.">\r\n";
if (!$sendmail) {
$error = 1;
$mailerror = 1;
}
if ($error == 1) {
echo "<title>Emailer Error</title>";
if ($dberror == 1) {
echo "<center><b>Error</b> - Cannot add to database.</center>";
echo "<center>".$dberrordesc."</center>";
} if ($mailerror == 1) {
echo "<center><b>Error</b> - Cannot send mail.</center>";
}
} else {
$headerlocation = "Location: ".$gotourl;
header($headerlocation);
}

?>

This is the reply e-mail that I receive :

Dress - 819 Fernhill Rd
> Carthage,N.C. U.S.A.
> Ail -
> X -
> Me - Paul Oltesvig
> One - 929-632-6475
> Ery - Booking water shuttle to Brod Bay
> Saturday Feb.4
> 2 adults

Replied 09 Feb 2006 19:26:37
09 Feb 2006 19:26:37 Roddy Dairion replied:
Very messy just send the php and mailing code

Reply to this topic