Skip to main content
Participating Frequently
Jul 10, 2020 7:29 PM UTC
Answered

Error: Special Characters Must Be Escaped

Hello. I'm attempting to put php code (for the first time) in an html document. I'm getting a "Special Characters Must be Escaped" error at the opening and closing tags of the php code. I'll post all the code I'm using but the php code will eventually be placed in a separate document for the form element to action to. Any help would be greatly appreciated.

 

<!DOCTYPE HTML>
<html>
<body>
<form name="photosubmission form" action="photoform-to-email.php"
<form name="photosubmissionform" action="photoform-to-email.php>
<label for="fname">First Name:</label><br>
<input type="text" id="fname" name="fname" placeholder="John" required><br>
<label for="lname">Last Name:</label><br>
<input type="text" id="lname" name="lname" placeholder="Doe" required><br>
<label for="phone">Phone Number:</label><br>
<input type="tel" id="phone" name="phone" class="phone" placeholder="123.456.7890" pattern="[0-9]{3}.[0-9]{3}.[0-9]{4}"><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" class="email" placeholder="johndoe@gmail.com" required><br>
<label for="image">Image File</label><br>
<input type="file" id="image" name="image" multiple>
<input type="submit" value="Submit">
</form>
</body>
</html>

 

<?php
if(!isset{$_POST['submit']))
{
echo "Error! You need to submit the form!";
}

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$file = $_POST['file'];

if(empty($fname) || empty($lname))
{ echo "Please enter your full name.";
exit;
}

if(empty($email))
{ echo "Please enter a valid email address.";
exit;
}

$email_from = 'marketing@cittrucks.com';
$email_subject = "New Photo Contest Submission";
$email_body = "You have received a new submission from $name. \n".
"email address: $visitor_email\n".
"Here is the submission: \n $message".

$to = "marketing@cittrucks.com";
$headers = "From: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);


function IsInjected($str)
{
$injections = array('(\n+);,
'(\r+)',
'(\t+)',
'(%0A+)',
'(%08+)',
'(%09+)'
$inject = join('|', $injections);
$inject = "/$inject/i";

if(preg_match($inject,$str))
{return true;
}
else
{return false;
}

if(IsInjected($email))
{
echo "Please enter a valid email address.";
exit;
}
?>

This topic is closed to new replies. Start a new post to keep the conversation going.
Jon Fritz
Jon FritzCorrect answer
Community Expert
Jul 13, 2020 2:01 PM UTC

DW's linter will show errors when you use php tags inside a file saved with the .html extension. It doesn't make a difference what you have selected in the bottom of the document window.

It uses a different error checker when the page is saved as .php and won't give the same error (the special characters must be escaped on all <?php> tags one). 

3 replies

Jon Fritz
Community Expert
Jon FritzCommunity ExpertCorrect answer
Community Expert
Jul 13, 2020 2:01 PM UTC

DW's linter will show errors when you use php tags inside a file saved with the .html extension. It doesn't make a difference what you have selected in the bottom of the document window.

It uses a different error checker when the page is saved as .php and won't give the same error (the special characters must be escaped on all <?php> tags one). 

Translate
Nancy OShea
Community Expert
Community Expert
Jul 10, 2020 11:07 PM UTC

Are you working with valid code inside a .php document?  See screenshot.

 

 

Translate
Nancy O'Shea— Product User & Community Expert
Participating Frequently
Jul 10, 2020 7:31 PM UTC

I was in the process of editing lines 4 and 5 so please ignore those.

Translate