jamesclues Posted February 27, 2009 Share Posted February 27, 2009 PHP Contact form Send Below. Line 54 where the error says is ?> at the end please can someone help me.. <? if($_POST["send"]) { //collect post variables $name = $_POST["name"]; $address = $_POST["address"]; $town = $_POST["town"]; $postocde = $_POST["postocde"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $enquiry = $_POST["enquiry"]; //build email body $body .= "Name: $name \n"; $body .= "Address: $address \n"; $body .= "Town: $town \n"; $body .= "Postcode: $postcode \n"; $body .= "Telephone: $telephone \n"; $body .= "Email: $email \n"; $body .= "Enquiry: $enquiry \n"; //create email headers $headers = 'From: '.$email. "\r\n" . 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send $send = mail("[email protected]","Online Enquiry",$body,$headers); ?> <? if($_POST["send"]) { //collect post variables $name = $_POST["name"]; $email = $_POST["email"]; //build email body $body .= "Name: $name \n"; $body .= "Thank you for your Enquiry \n"; //create email headers $headers = "From: '[email protected]' \r\n". 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send $send = mail("$email","Online Enquiry",$body,$headers); ?> Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/ Share on other sites More sharing options...
Mark Baker Posted February 27, 2009 Share Posted February 27, 2009 Generally that error means you're opening braces and not closing them, so try and match up all your { } and see where there's a closing brace missing Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772437 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 It's the one that opens here if($_POST["send"]) { and here if($_POST["send"]) { Hey... these are the only two braces in your code, and you didn't close either of them! Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772448 Share on other sites More sharing options...
jamesclues Posted February 27, 2009 Author Share Posted February 27, 2009 Now I get Notice: Undefined index: send in send.php on line 2 if($_POST["send"]) { Notice: Undefined index: send in send.php on line 34 if($_POST["send"]) { Full Code Below <? if($_POST["send"]) { //collect post variables $name = $_POST["name"]; $address = $_POST["address"]; $town = $_POST["town"]; $postocde = $_POST["postocde"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $enquiry = $_POST["enquiry"]; //build email body $body .= "Name: $name \n"; $body .= "Address: $address \n"; $body .= "Town: $town \n"; $body .= "Postcode: $postcode \n"; $body .= "Telephone: $telephone \n"; $body .= "Email: $email \n"; $body .= "Enquiry: $enquiry \n"; //create email headers $headers = 'From: '.$email. "\r\n" . 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send $send = mail("[email protected]","Online Enquiry",$body,$headers);} ?> <? if($_POST["send"]) { //collect post variables $name = $_POST["name"]; $email = $_POST["email"]; //build email body $body .= "Name: $name \n"; $body .= "Thank you for your Enquiry \n"; //create email headers $headers = "From: '[email protected]' \r\n". 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send $send = mail("$email","Online Enquiry",$body,$headers);} ?> Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772525 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 It is because, you don't check if $_POST['send'] exists before checking its value. if(isset($_POST["send"]) && $_POST["send"]) { Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772542 Share on other sites More sharing options...
shadiadiph Posted February 27, 2009 Share Posted February 27, 2009 incorrect $end nearly always means you are missing a } somewhere if you open a { you have to close it somewhere.} which it seems you have but i think your if loop is confusing itself as you have the same if statement with two same values it doesn't know what to do. $send = mail( doesn't make sense either. try this if the name of the submit button is send it will do something if it is input typesubmit name=submit then you need to change $_POST["send"] tp $_POST["submit"] <? header ("Location: thankyou.php"); if($_POST["send"]) { //collect post variables $name = $_POST["name"]; $address = $_POST["address"]; $town = $_POST["town"]; $postocde = $_POST["postocde"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $enquiry = $_POST["enquiry"]; //build email body $body .= "Name: $name \n"; $body .= "Address: $address \n"; $body .= "Town: $town \n"; $body .= "Postcode: $postcode \n"; $body .= "Telephone: $telephone \n"; $body .= "Email: $email \n"; $body .= "Enquiry: $enquiry \n"; //create email headers $headers = 'From: '.$email. "\r\n" . 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send mail("[email protected]","Online Enquiry",$body,$headers); //collect post variables $name = $_POST["name"]; $email = $_POST["email"]; //build email body $body .= "Name: $name \n"; $body .= "Thank you for your Enquiry \n"; //create email headers $headers = "From: '[email protected]' \r\n". 'Reply-To: ' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //send mail("$email","Online Enquiry",$body,$headers); } else { header ("Location: index.php"); } exit; ?> not sure about your email headers etc as I am not familiar with X mailer Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772565 Share on other sites More sharing options...
shadiadiph Posted February 27, 2009 Share Posted February 27, 2009 but this would be how i would do it assuming the submit value on your forms name is submit. <? header("Location: thankyou.php"); if($_POST["submit"]) { //collect post variables $name = $_POST["name"]; $address = $_POST["address"]; $town = $_POST["town"]; $postocde = $_POST["postocde"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $enquiry = $_POST["enquiry"]; $to = "[email protected]"; $subject = "Online Enquiry"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>Inquiry</title> </head> <body> Name: $name <br /> Address: $address <br /> Town: $town <br /> Postcode: $postcode <br /> Telephone: $telephone <br /> Email: $email <br /> Enquiry: $enquiry <br /> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); $to = "$email"; $subject = "Online Enquiry"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>Inquiry</title> </head> <body> $name <br /> <p>Thank you for your Enquiry.</p> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); } else { header("Location: index.php"); } exit; ?> Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772593 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 shadiadiph: you put header("Location: thankyou.php"); as the very first line of the code. Are you aware, that nothing below will ever be executed? Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772664 Share on other sites More sharing options...
shadiadiph Posted February 27, 2009 Share Posted February 27, 2009 oops sorry you are right just too tired i never usually use if $_POST on any of mine just pasted around the template i have saved. that i keep having to post here to help people over and over again. if($_POST["submit"]) { //collect post variables $name = $_POST["name"]; $address = $_POST["address"]; $town = $_POST["town"]; $postocde = $_POST["postocde"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $enquiry = $_POST["enquiry"]; header ("Location: thankyou.php"); $to = "[email protected]"; header is usually there on my script sorry Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772707 Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 Still this does nothing... I think you wanted to put it at least after mail() function Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772712 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 it works for me Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-772983 Share on other sites More sharing options...
Mchl Posted February 28, 2009 Share Posted February 28, 2009 Doing what? There are only variable assignments before header redirection. This script does nothing. Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-773188 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 in the last post i said just move the header so you are saying this will do nothing? <? header("Location: thankyou.php"); if($_POST["submit"]) { //collect post variables $name = $_POST["name"]; $address = $_POST["address"]; $town = $_POST["town"]; $postocde = $_POST["postocde"]; $telephone = $_POST["telephone"]; $email = $_POST["email"]; $enquiry = $_POST["enquiry"]; header("Location: thankyou.php"); $to = "[email protected]"; $subject = "Online Enquiry"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>Inquiry</title> </head> <body> Name: $name <br /> Address: $address <br /> Town: $town <br /> Postcode: $postcode <br /> Telephone: $telephone <br /> Email: $email <br /> Enquiry: $enquiry <br /> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); $to = "$email"; $subject = "Online Enquiry"; $MsgHeader = "From: WEBSITE NAME <[email protected]>\n"; $MsgHeader .= "MIME-Version: 1.0\n"; $MsgHeader .= "Content-type: text/html; charset=iso-8859-1"; $MsgBody = " <html> <head> <title>Inquiry</title> </head> <body> $name <br /> <p>Thank you for your Enquiry.</p> </body> </html>"; mail($to, $subject, $MsgBody, $MsgHeader); } else { header("Location: index.php"); } exit; ?> Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-773197 Share on other sites More sharing options...
Mchl Posted February 28, 2009 Share Posted February 28, 2009 Ok. I did some testing and you're right. The location header is not send to browser immediately but after script finishes executing. My fault :oops: Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-773200 Share on other sites More sharing options...
shadiadiph Posted February 28, 2009 Share Posted February 28, 2009 thats ok i used to put my headers at the botom but someone told me not to the header has to come before for it to execute properly this script works fine Link to comment https://forums.phpfreaks.com/topic/147138-parse-error-syntax-error-unexpected-end-in-sendphp/#findComment-773205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.