Page 1 of 2

php not working - was working yesterday! please help

Posted: Wed Feb 07, 2007 8:04 am
by mccannio
Hi there,

I have been pulling my hair out with this today. It is some code to process a form and then send the results via email. It was working fine yesterday but not it just keeps jumping to the error page!

I would really appreciate it if someone could help me!

Code: Select all

<?php

$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$EmailTo = "paul.mccann@firstfound.co.uk".",";
$Emailto.= $EmailFrom;
$Subject = "Photocopier Enquiry";
$ColourCopiers = Trim(stripslashes($_POST['ColourCopiers'])); 
$BlackandWhiteCopiers = Trim(stripslashes($_POST['BlackandWhiteCopiers'])); 
$Facsimilies = Trim(stripslashes($_POST['Facsimilies'])); 
$Purchase = Trim(stripslashes($_POST['Purchase'])); 
$Lease = Trim(stripslashes($_POST['Lease'])); 
$Name = Trim(stripslashes($_POST['Name'])); 
$Company = Trim(stripslashes($_POST['Company'])); 
$PostCode = Trim(stripslashes($_POST['PostCode'])); 
$Email = Trim(stripslashes($_POST['EmailFrom'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
$Brochure = Trim(stripslashes($_POST['Brochure']));
$Model = Trim(stripslashes($_POST['Model']));



$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}


$Body = "";
$Body .= "ColourCopiers: ";
$Body .= $ColourCopiers;
$Body .= "\n";
$Body .= "BlackandWhiteCopiers: ";
$Body .= $BlackandWhiteCopiers;
$Body .= "\n";
$Body .= "Facsimilies: ";
$Body .= $Facsimilies;
$Body .= "\n";
$Body .= "Purchase: ";
$Body .= $Purchase;
$Body .= "\n";
$Body .= "Lease: ";
$Body .= $Lease;
$Body .= "\n";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "PostCode: ";
$Body .= $PostCode;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$Body .= "Brochure: ";
$Body .= $Brochure;
$Body .= "\n";
$Body .= "Model: ";
$Body .= $Model;
$Body .= "\n";


$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");



if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.htm\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.php\">";
}
?>

Posted: Wed Feb 07, 2007 8:09 am
by superdezign

Code: Select all

$Emailto.= $EmailFrom;
Did you mean $EmailTo? You forgot to capitalize the 't.'

Posted: Wed Feb 07, 2007 8:14 am
by mccannio
sorry, that bit has been taken out ( I'm not using it now) but the code still jumps to error.htm ! I am probably missing something really simple because I have been looking at it all day! Can anyone see where I am going wrong?

Posted: Wed Feb 07, 2007 8:23 am
by superdezign
To error.htm? Well that means you're not getting your posted variables. Check what you're getting in $_POST['EmailFrom'].

Posted: Wed Feb 07, 2007 8:32 am
by mccannio
the info is being passed on. i printed out 'EmailFrom' using echo command and it was fine.

Posted: Wed Feb 07, 2007 8:39 am
by mccannio
hello everyone. any suggestions with this? it is driving me mad!

Posted: Wed Feb 07, 2007 8:42 am
by superdezign
Well the problem is either in where you get $EmailFrom or where you check $EmailFrom.

echo Trim($EmailFrom) and $validationOK before and after the if statement to see whats happening.

Posted: Wed Feb 07, 2007 9:00 am
by volka
And let the script beginn with

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);

$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
and change all
print "<meta http-equiv=\"refresh\" content=\"0;
to

Code: Select all

print "<meta http-equiv=\"refresh\" content=\"20;
for testing purposes.

Posted: Wed Feb 07, 2007 9:12 am
by mccannio
thanks for that. that code produced the following errors:

Notice: Undefined index: EmailFrom in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 6

Notice: Undefined variable: Emailto in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 8

Notice: Undefined index: ColourCopiers in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 10

Notice: Undefined index: BlackandWhiteCopiers in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 11

Notice: Undefined index: Facsimilies in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 12

Notice: Undefined index: Purchase in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 13

Notice: Undefined index: Lease in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 14

Notice: Undefined index: Name in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 15

Notice: Undefined index: Company in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 16

Notice: Undefined index: PostCode in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 17

Notice: Undefined index: EmailFrom in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 18

Notice: Undefined index: Tel in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 19

Notice: Undefined index: Message in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 20

Notice: Undefined index: Brochure in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 21

Notice: Undefined index: Model in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 22



Make any sense to anyone?

Posted: Wed Feb 07, 2007 9:53 am
by volka
It means superdezign was right and you're not getting the parameters posted. There is no EmailFrom, EmailTo ... Model in $_POST.
Let's see what you actually got, let the script start with

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);

echo 'version: ', phpversion(), "<br />\n";
echo 'uname: ', php_uname(), "<br />\n";
echo '<pre>POST: ', var_export($_POST), "</pre>\n";
echo '<pre>GET: ', var_export($_GET), "</pre>\n";
echo '<pre>REQUEST: ', var_export($_REQUEST), "</pre>\n";
die();

$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));

Posted: Wed Feb 07, 2007 9:56 am
by mccannio
ok , that code produced this:






Code: Select all

version: 4.3.10-18
uname: Linux web2 2.6.8-2-686 #1 Mon Jan 24 03:58:38 EST 2005 i686

POST: array (
  'ColourCopiers' => 'Yes',
  'Name' => 'paul',
  'Company' => 'first found ',
  'PostCode' => 'm1 2hf',
  'EmailFrom' => 'mccap8@aol.com',
  'Tel' => '01619093411',
  'Message' => 'test',
  'Brochure' => 'Yes',
  'Model' => '',
  'submit' => 'Submit',
)

GET: array (
)

REQUEST: array (
  'ColourCopiers' => 'Yes',
  'Name' => 'paul',
  'Company' => 'first found ',
  'PostCode' => 'm1 2hf',
  'EmailFrom' => 'mccap8@aol.com',
  'Tel' => '01619093411',
  'Message' => 'test',
  'Brochure' => 'Yes',
  'Model' => '',
  'submit' => 'Submit',
  '__utmz' => '122014937.1163514914.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none)',
  '__utma' => '122014937.623632341.1163514914.1170852600.1170863661.30',
  '__utmc' => '122014937',
  '__utmb' => '122014937',
)




Any suggestions?

Posted: Wed Feb 07, 2007 10:07 am
by volka
try

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);
if ( get_magic_quotes_gpc() ) {
	$_POST = array_map('stripslashes', $_POST);
}

$fields = array(
		'EmailFrom','ColourCopiers','BlackandWhiteCopiers',
		'Facsimilies','Purchase','Lease','Name',
		'Company','PostCode','Email','Tel','Message',
		'Brochure','Model'
	);

$errors = array();

$Body = "...\n";
foreach($fields as $f) {
	if ( !isset($_POST[$f]) ) {
		$errors[] = 'missing field ' . $f;
	}
	else{
		$Body .= $f . ': ' . $_POST[$f] . "\n";
	}
}

if ( empty($_POST['EmailFrom']) ) {
	$errors[] = 'invalid email address';
}

if ( !empty($errors) ) {
	echo '<p>', join("</p>\n<p>", $errors), "</p>\n";
	echo '<pre>POST: ', var_export($_POST), "</pre>\n"; 
	die();
}


$EmailTo = "paul.mccann@firstfound.co.uk".",";
$Emailto.= $EmailFrom;
$Subject = "Photocopier Enquiry";

echo "<pre>mail($EmailTo, $Subject, $Body, \"From: <$EmailFrom>\")</pre>\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

if ($success){
  print '<meta http-equiv="refresh" content="20;URL=thanks.htm">';
}
else{
  print '<meta http-equiv="refresh" content="20;URL=contact.php">';
}
?>

Posted: Wed Feb 07, 2007 10:20 am
by mccannio
that came back with the following errors:

missing field BlackandWhiteCopiers

missing field Facsimilies

missing field Purchase

missing field Lease

missing field Email

missing field Brochure

POST: array (
'ColourCopiers' => 'Yes',
'Name' => 'aaaaaaaaaaaaaa',
'Company' => 'adasdsda',
'PostCode' => 'adasd',
'EmailFrom' => 'aaaaaaaaaaaaaaaaaa',
'Tel' => '01619093411',
'Message' => 'aa',
'Model' => '',
'submit' => 'Submit',
)


Any ideas?

Posted: Wed Feb 07, 2007 10:24 am
by mccannio
that now gives me the following errors:




Notice: Undefined variable: EmailFrom in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 41

mail(paul.mccann@firstfound.co.uk,, Photocopier Enquiry, ...
EmailFrom: aaaaaaaaaaaaaaaaaa
ColourCopiers: Yes
BlackandWhiteCopiers: Yes
Facsimilies: Yes
Purchase: Yes
Lease: Yes
Name: aaaaaaaaaaaaaa
Company: adasdsda
PostCode: adasd
Tel: 01619093411
Message: aa
Brochure: Yes
Model: j
, "From: <>")


Notice: Undefined variable: EmailFrom in /disk1/www/www.claritycopiershw.co.uk/htdocs/test1 ... ontact.php on line 42

Posted: Wed Feb 07, 2007 10:38 am
by volka

Code: Select all

$EmailFrom = $_POST['EmailFrom'];
$EmailTo = "paul.mccann@firstfound.co.uk".",";
$Emailto.= $EmailFrom;
$Subject = "Photocopier Enquiry";
you might also want to check the email address more thorough, see http://pear.php.net/manual/en/package.m ... sslist.php