Jump to content

Email form PHP Syntax error


Recommended Posts

Can anyone help, im setting up an email form and it is returning this error.
 
**Parse error: syntax error, unexpected 'isInjected' (T_STRING), expecting '(' in /storage/ssd4/339/5596339/public_html/send_mail.php on line 21**
 
**Html code:**
 
    <form action="send_mail.php" method="post">
    <p><br>
    <input name="Name" type="text" style="width: 325px; height: 40px" placeholder="Your Name *" required><p>
    <input name="Email" type="text" style="width: 325px; height: 40px" placeholder="Email Address *" required><p>
    <input name="Telephone" type="text" style="width: 325px; height: 40px" placeholder="Telephone Number *" required><p>
    <select name="Type" style="width: 325px; height: 40px" required>
    <option value="" disabled selected>Type of Move *
    </option>
    <option value="Home Move Only">Home Move Only</option>
    <option value="Business Move Only">Business Move Only</option>
    <option value="Home Move and Storage">Home Move and Storage</option>
    <option value="Business Move and Storage">Business Move and Storage</option>
    <option value="General Move">General Move</option>
    </select><p>
    <input name="From" type="text" style="width: 325px; height: 40px" placeholder="Moving From (Postcode) *" required><p>
    <input name="To" type="text" style="width: 325px; height: 40px" placeholder="Moving To (Postcode) *" required><p>
    <button name="Abutton1" style="width: 325px; height: 40px;" class="btn1" type="submit" value="Submit">Submit
    </button>
    <p align="left">
    <input name="Checkbox1" type="checkbox" required><span class="style7">I  accepted.</span></form>

**PHP Code**

    <?php
    $webmaster_email = "email@hotmail.co.uk";
    $feedback_page = "feedback_form.html";
    $error_page = "error_message.html";
    $thankyou_page = "thank_you.html";
    $Email = $_REQUEST['email'] ;
    $Telephone = $_REQUEST['Telephone'] ;
    $Name = $_REQUEST['Name'] ;
    $Type = $_REQUEST['Type'] ;
    $From = $_REQUEST['From'] ;
    $To = $_REQUEST['To'] ;
    $Checkbox1 = $_REQUEST['Checkbox1'] ;
    $msg = 
    "Name: " . $Name . "\r\n" . 
    "Email: " . $Email . "\r\n" . 
    "Telephone: " . $Telephone . "\r\n" . 
    "Type: " . $Type . "\r\n" .
    "From: " . $From . "\r\n" .
    "To: " . $To . "\r\n" .
    "Checkbox1: " . $Checkbox1 . "\r\n" .	
    function isInjected($str) {
	$injections = array('(\n+)',
	'(\r+)',
	'(\t+)',
	'(%0A+)',
	'(%0D+)',
	'(%08+)',
	'(%09+)'
	);
	$inject = join('|', $injections);
	$inject = "/$inject/i";
	if(preg_match($inject,$str)) {
		return true;
	}
	else {
		return false;
	}
    }
    if (!isset($_REQUEST['Email'])) {
    header( "Location: $feedback_page" );
    }
    elseif (empty($Name) || empty($Email)) {
    header( "Location: $error_page" );
    }
    elseif (empty($Name) || empty($Email) || empty($Telephone) || empty($Type) || empty($From) || empty($To)) {
    header( "Location: $error_page" );
    }
    else {
    mail( "$webmaster_email", "Feedback Form Results", $msg );
    header( "Location: $thankyou_page" );
    }
    ?>

Please help this is driving me mad.

 

Cheers

 

Richard

Link to comment
Share on other sites

How would i go about fixing this issue?

 

As Barand mentioned, the following statement needs to be closed before you define the isInjected() function:

"Checkbox1: " . $Checkbox1 . "\r\n" .

You just need to replace the concatenation character with a semi-colon.

"Checkbox1: " . $Checkbox1 . "\r\n";
Link to comment
Share on other sites

And stop using the global REQUEST array - use the one that matters in each case whether it be $_POST or $_GET

 

And learn to place your functions outside the flow of your logic. Why interrupt your code with some extraneous block that is going to be used all over the place? Place functions at the end of your mainstream php code.

 

And add a 'from' address to your (missing) headers argument of the mail call. It is required and is not usually included in the .ini file so you should be sure to add it here. Read the manual.

 

Are confused now? :)

Link to comment
Share on other sites

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.