Jump to content

**please help** simple php contact us form help


cmbcorp

Recommended Posts

Hi Guys/Gals,

 

Having an issue with my php form..

 

Basically i want to make more than 2 fields mandatory..

 

Now everything worked ok with only the name and the email as mandatory, then i started playing around with it, here was the original code that "worked"

 

<?php 
$to = $_REQUEST['sendto'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$headers = "From: $from"; 
$subject = "Counter Intelligence POS - Support Help Desk Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"ciposver"} = "CIPosVersion"; 
$fields{"ciofficever"} = "CIOfficeVersion"; 
$fields{"cios"} = "CIOperatingSystems"; 
$fields{"Message"} = "CIDetailedIssue"; 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!.";

if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send) 
{header( "Location: http://www.counterintelligencepos.com.au/thankyou.html" );} 
else 
{print "We encountered an error sending your mail, please notify [email protected]"; } 
}
}
?>

 

then i played around with it, this is what i done:

 

<?php 
$to = $_REQUEST['sendto'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$company = $_REQUEST['Company'] ;
$phone = $_REQUEST['Phone'] ;  

$headers = "From: $from"; 
$subject = "Counter Intelligence POS - Support Help Desk Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"ciposver"} = "CIPosVersion"; 
$fields{"ciofficever"} = "CIOfficeVersion"; 
$fields{"cios"} = "CIOperatingSystems"; 
$fields{"Message"} = "CIDetailedIssue"; 

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!.";

if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
if($phone == '') {print "You have not entered a phone number, please go back and try again";} 
else { 
if($company == '') {print "You have not entered a company name, please go back and try again";} 
else { 

$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send) 
{header( "Location: http://www.counterintelligencepos.com.au/thankyou.html" );} 
else 
{print "We encountered an error sending your mail, please notify [email protected]"; } 
}
}
?>

 

WHen i go to run my form, i get the following error message:

 

 

Parse error: syntax error, unexpected $end in /home/counteri/public_html/contact_support.php on line 44

 

Am i doing something wrong?

 

Not sure why i am getting these errors.

 

Really appriciate your help guys..

 

Thanks.

 

Jason.

One extra brace at the last line

 

hope this works ;)

 

<?php 
$to = $_REQUEST['sendto'] ; 
$from = $_REQUEST['Email'] ; 
$name = $_REQUEST['Name'] ; 
$company = $_REQUEST['Company'] ;
$phone = $_REQUEST['Phone'] ;  

$headers = "From: $from"; 
$subject = "Counter Intelligence POS - Support Help Desk Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"ciposver"} = "CIPosVersion"; 
$fields{"ciofficever"} = "CIOfficeVersion"; 
$fields{"cios"} = "CIOperatingSystems"; 
$fields{"Message"} = "CIDetailedIssue"; 

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!.";

if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
if($phone == '') {print "You have not entered a phone number, please go back and try again";} 
else { 
if($company == '') {print "You have not entered a company name, please go back and try again";} 
else 
{ 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
	if($send) 
	{
	header( "Location: http://www.counterintelligencepos.com.au/thankyou.html" );
	} 
	else 
	{
	print "We encountered an error sending your mail, please notify [email protected]"; 
	} 
}

?>

If you get Undefined index, so please declare all variables null at the beginning ;)

 

<?php 
$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company'];
$phone = $_REQUEST['Phone'];  

$headers = "From: $from"; 
$subject = "Counter Intelligence POS - Support Help Desk Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"ciposver"} = "CIPosVersion"; 
$fields{"ciofficever"} = "CIOfficeVersion"; 
$fields{"cios"} = "CIOperatingSystems"; 
$fields{"Message"} = "CIDetailedIssue"; 

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!.";

if($from=='') {print "You have not entered an email, please go back and try again";} 
if($name=='') {print "You have not entered a name, please go back and try again";} 
if($phone=='') {print "You have not entered a phone number, please go back and try again";} 
if($company=='') {print "You have not entered a company name, please go back and try again";} 

else 
{ 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
	if($send) 
	{
	header("Location: http://www.counterintelligencepos.com.au/thankyou.html");
	} 
	else 
	{
	echo "We encountered an error sending your mail, please notify [email protected]"; 
	}
}

?>

hi thanks so much for your help...

 

i tried your code and when i didnt enter something in the phone number field, it sent the email, but before it sent the email it displayed the error message

:

You have not entered a phone number, please go back and try again

Warning: Cannot modify header information - headers already sent by (output started at /home/counteri/public_html/contact_support.php:33) in /home/counteri/public_html/contact_support.php on line 42

 

Not sure why its sending the email without the phone number field filled in.. any ideas?

 

THanks for your help..

 

cheers

Now try this ;)

 

<?php ob_start();
$to = $_REQUEST['sendto']; 
$from = $_REQUEST['Email']; 
$name = $_REQUEST['Name']; 
$company = $_REQUEST['Company'];
$phone = $_REQUEST['Phone'];  

$headers = "From: $from"; 
$subject = "Counter Intelligence POS - Support Help Desk Form"; 

$fields = array(); 
$fields{"Name"} = "Name"; 
$fields{"Company"} = "Company"; 
$fields{"Email"} = "Email"; 
$fields{"Phone"} = "Phone"; 
$fields{"ciposver"} = "CIPosVersion"; 
$fields{"ciofficever"} = "CIOfficeVersion"; 
$fields{"cios"} = "CIOperatingSystems"; 
$fields{"Message"} = "CIDetailedIssue"; 

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b)
{ 
$body.=sprintf("%20s: %s\n",$b,$_REQUEST[$a]);
} 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for for your query. A support representitive will be in contact with you shortly!.";

if($from=='') {print "You have not entered an email, please go back and try again";} 
if($name=='') {print "You have not entered a name, please go back and try again";} 
if($phone=='') {print "You have not entered a phone number, please go back and try again";} 
if($company=='') {print "You have not entered a company name, please go back and try again";} 
$isfreeofErrors=1;

if ($isfreeofErrors==1)
{ 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
	if($send) 
	{
	header("Location: http://www.counterintelligencepos.com.au/thankyou.html");
	} 
	else 
	{
	echo "We encountered an error sending your mail, please notify [email protected]"; 
	}
} else {
echo "Something is still wrong.";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.