Help w/ php errors within script to email an html form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdminCyn
    New Member
    • Apr 2010
    • 4

    Help w/ php errors within script to email an html form

    I am working on a project to update our website functionality; mainly I am suppose to create an HTML form for prospective tenants to fill out and submit via email; I have the html form done and looking wonderful but an struggling with the php script to email the form contents; I have written a php script to email a form; I keep getting these errors

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in //Forms/contact.php on line 2
    Parse error: syntax error, unexpected T_VARIABLE in //Forms/contact.php on line 3

    Here is my php script to handle the email

    Code:
    <?php 
     $to = $_REQUEST['sendto'] ; 
     $from = $_REQUEST['Email'] ; 
     $name = $_REQUEST['Name'] ; 
     $headers = "From: $from"; 
     $subject = "Web Contact Data"; 
     
     $fields = array(); 
     $fields{"element_49"} = "Property Reference"; 
     $fields{"element_48"} = "Desired Occupancy Date"; 
     $fields{"element_2"} = "Name"; 
     $fields{"element_9"} = "Date of Birth"; 
     $fields{"element_3"} = "Current Address"; 
     $fields{"element_4"} = "Phone Number"; 
     $fields{"element_5"} = "Email"; 
     $fields{"element_6"} = "Web Site"; 
     $fields{"element_7"} = "How long at Current Address"; 
     $fields{"element_45"} = "Rent/Own"; 
     $fields{"element_10"} = "Monthly Rent"; 
     $fields{"element_11"} = "Reason For Leaving"; 
     $fields{"element_12"} = "Building Manager/Landlord/Listing"; 
     $fields{"element_13"} = "Phone Number"; 
     $fields{"element_28"} = "Previous Address"; 
     $fields{"element_14"} = "How Long at Previous Address"; 
     $fields{"element_46"} = "Rent/Own"; 
     $fields{"element_15"} = "Monthly Rent"; 
     $fields{"element_16"} = "Reason for Leaving"; 
     $fields{"element_29"} = "Building Manager/Landlord/Listing "; 
     $fields{"element_30"} = "Phone Number"; 
     $fields{"element_17"} = "Employer"; 
     $fields{"element_18"} = "Position"; 
     $fields{"element_19"} = "How Long "; 
     $fields{"element_20"} = "Supervisor"; 
     $fields{"element_31"} = "Phone Number"; 
     $fields{"element_32"} = "Previous Employer"; 
     $fields{"element_33"} = "Position"; 
     $fields{"element_34"} = "How Long "; 
     $fields{"element_35"} = "Supervisor"; 
     $fields{"element_36"} = "Phone Number"; 
     $fields{"element_21"} = "Current Gross Monthly Income"; 
     $fields{"element_22"} = "Number of Auto's"; 
     $fields{"element_23"} = "Make(s)"; 
     $fields{"element_24"} = "Model(s)"; 
     $fields{"element_25"} = "License #(s)"; 
     $fields{"element_26"} = "Name Of Personal Reference"; 
     $fields{"element_38"} = "Phone Number"; 
     $fields{"element_27"} = "Name Of Personal Reference"; 
     $fields{"element_37"} = "Phone Number"; 
     $fields{"element_39"} = "Emergency Contact"; 
     $fields{"element_40"} = "Phone Number"; 
     $fields{"element_41"} = "Email"; 
     $fields{"element_42"} = "Full Names of all Other Adult Persons"; 
     $fields{"element_43"} = "Full Names of all Minor Residents "; 
     $fields{"element_47"} = "Insurance"; 
    
    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ 	$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
     
     $headers2 = "From: me@newhere.com"; 
     $subject2 = "Thank you for contacting us"; 
     $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.newhere.com";
     
     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.YourDomain.com/thankyou.html" );} 
     else 
     {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } 
     }
    }
     ?>

    Any help on these would be appreciated! I have also attached my html form for the data input! (saved as a .txt file)
    Attached Files
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    You're using curly braces {} on an array, the correct syntax is brackets []

    $fields['elemnt2'] = 'Something';

    And why are you naming them elements?

    shouldn't be easier to use the actual names?

    $field['address'] = "address"?


    Dan

    Comment

    Working...