Jump to content

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


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: noreply@counterintelligence.com.au"; 
$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 sales@counterintelligencepos.com.au"; } 
}
}
?>

 

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: noreply@counterintelligence.com.au"; 
$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 sales@counterintelligencepos.com.au"; } 
}
}
?>

 

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: noreply@counterintelligence.com.au"; 
$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 sales@counterintelligencepos.com.au"; 
	} 
}

?>

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: noreply@counterintelligence.com.au"; 
$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 sales@counterintelligencepos.com.au"; 
	}
}

?>

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: noreply@counterintelligence.com.au"; 
$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 sales@counterintelligencepos.com.au"; 
	}
} else {
echo "Something is still wrong.";
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.