Contact Form Parse Error

OK. I have not received any help from GoDaddy at all. Even with their gdform.php. So I have decided to start coding my own php contact form.

Error Message from GoDaddy:

Parse error: syntax error, unexpected T_STRING, expecting ']' in D:\Hosting\html\scripts\contact.php on line 12

My Code:

[php]

<?php // if the url field is empty if(isset($_POST['url']) && $_POST['url'] == ''){ // put your email address here $youremail = '[email protected]'; // prepare a response fields of the message $body = "This is the form that was just submitted: First Name: $_POST[01_First_Name] Last Name: $_POST[02_Last_Name] E-Mail: $_POST[03_Email] Phone Number: $_POST[04_Phone] Reason/Comments: $_POST[05_Description]"; // Use the submitters email if they supplied one // (and it isn't trying to hack your form). // Otherwise send from your email address. if( $_POST['03_Email'] && !preg_match( "/[\r\n]/", $_POST['03_Email']) ) { $headers = "From: $_POST[03_Email]"; } else { $headers = "From: $youremail"; } // finally, send the message mail($youremail, $subject, $body, $headers); } // otherwise, let the spammer think that they got their message through header("Location: http://".$_SERVER["HTTP_HOST"]."/".$_POST["redirect"]); ?>

[/php]

Any takers on this version of my problem…

I imagine it’s caused by trying to access an array element incorrectly… $array[key], If the key is an integer you can use array[1] if the key is a string you need to use quotes around it: $array[‘string’]

I cant see all the code in my phone but check your if statements, make sure they’re wrapped properly, not missing the ) at the end. Thats usually what causes that error

Semicolon is missing at the end of $_POST statement. Also, you are using numbers at the beginning of the Id (ex: First Name: $_POST[01_First_Name]) . Use: number at the end. ex: First Name: $_POST[First_Name_01]; This will fix the issue.
Find the corrected code below:
[php]

<?php // if the url field is empty if(isset($_POST['url']) && $_POST['url'] == ''){ // put your email address here $youremail = '[email protected]'; // prepare a response fields of the message $body = "This is the form that was just submitted: First Name: $_POST[First_Name]; Last Name: $_POST[Last_Name]; E-Mail: $_POST[Email]; Phone Number: $_POST[Phone]; Reason/Comments: $_POST[Description]"; // Use the submitters email if they supplied one // (and it isn't trying to hack your form). // Otherwise send from your email address. if( $_POST['Email'] && !preg_match( "/[\r\n]/", $_POST['Email']) ) { $headers = "From: $_POST[Email]"; } else { $headers = "From: $youremail"; } // finally, send the message mail($youremail, $subject, $body, $headers); } // otherwise, let the spammer think that they got their message through header("Location: http://".$_SERVER["HTTP_HOST"]."/".$_POST["redirect"]); ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service