PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mccannio
Forum Newbie
Posts: 13 Joined: Mon Feb 05, 2007 6:53 am
Post
by mccannio » Wed Feb 07, 2007 8:04 am
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\">";
}
?>
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Feb 07, 2007 8:09 am
Did you mean $EmailTo? You forgot to capitalize the 't.'
mccannio
Forum Newbie
Posts: 13 Joined: Mon Feb 05, 2007 6:53 am
Post
by mccannio » Wed Feb 07, 2007 8:14 am
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?
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Feb 07, 2007 8:23 am
To error.htm? Well that means you're not getting your posted variables. Check what you're getting in $_POST['EmailFrom'].
mccannio
Forum Newbie
Posts: 13 Joined: Mon Feb 05, 2007 6:53 am
Post
by mccannio » Wed Feb 07, 2007 8:32 am
the info is being passed on. i printed out 'EmailFrom' using echo command and it was fine.
mccannio
Forum Newbie
Posts: 13 Joined: Mon Feb 05, 2007 6:53 am
Post
by mccannio » Wed Feb 07, 2007 8:39 am
hello everyone. any suggestions with this? it is driving me mad!
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Wed Feb 07, 2007 8:42 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Feb 07, 2007 9:00 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Feb 07, 2007 9:53 am
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']));
mccannio
Forum Newbie
Posts: 13 Joined: Mon Feb 05, 2007 6:53 am
Post
by mccannio » Wed Feb 07, 2007 9:56 am
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?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Wed Feb 07, 2007 10:07 am
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">';
}
?>
mccannio
Forum Newbie
Posts: 13 Joined: Mon Feb 05, 2007 6:53 am
Post
by mccannio » Wed Feb 07, 2007 10:20 am
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?