Jump to content


Photo

Email form PHP Syntax error


  • Please log in to reply
4 replies to this topic

#1 richyunspoken

richyunspoken
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 01 May 2018 - 07:39 PM

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


Edited by richyunspoken, 01 May 2018 - 07:40 PM.


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,169 posts

Posted 01 May 2018 - 08:16 PM

    "Checkbox1: " . $Checkbox1 . "\r\n" .    
    function isInjected($str) {         |
                                        |
                                        concatenation operator

You are trying to concatenate the function definition with your string.


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 richyunspoken

richyunspoken
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 01 May 2018 - 08:42 PM

Thank you Barand for your reply.

How would i go about fixing this issue?

Any help would be appreciated.

I am still new to PHP and don't understand it all.

 

Thank you.



#4 cyberRobot

cyberRobot
  • Moderators
  • Much to Learn
  • 2,793 posts

Posted 01 May 2018 - 08:57 PM

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";


#5 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,194 posts
  • LocationVoorheesville NY

Posted 02 May 2018 - 12:05 PM

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? :)
JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users