Syntax error has occurred on php contact

Issues related to forms.
Post Reply
TrevH
 
 
Posts: 63
Joined: Wed Nov 26, 2014 3:31 pm
Location: UK
Contact:

Syntax error has occurred on php contact

Post by TrevH » Sun Feb 11, 2018 4:38 pm

Hi,
For some reason a contact form that that was working is now giving a syntax error message when the contact link is clicked instead of opening the form page... Any help is greatly apprieciated.

It's located in the code section above the <head> tags

Parse error: syntax error, unexpected '{' in /home/mysite.com/public_html/contact.php on line 87. I've marked line 87 with :arrow: if that helps?

<?php
if (session_id() == "")
{
session_start();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['formid'] == 'form1')
{
if (isset($_POST['captcha_code'],$_SESSION['random_txt']) && md5($_POST['captcha_code']) == $_SESSION['random_txt'])
{
unset($_POST['captcha_code'],$_SESSION['random_txt']);
}
else
{
echo '<b>The entered code was wrong.</b><br>';
echo '<a href="javascript:history.back()">Go Back</a>';
exit;
}
}
?>
<?php
function ValidateEmail($email)
{
$pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i';
return preg_match($pattern, $email);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['formid']) && $_POST['formid'] == 'form1')
{
$mailto = 'customer@privateemailaddress.com';
$mailfrom = isset($_POST['email']) ? $_POST['email'] : $mailto;
$subject = 'message from your website';
$message = 'Values submitted from web site form:';
$success_url = './thank_you.html';
$error_url = '';
$error = '';
$eol = "\n";
$boundary = md5(uniqid(time()));

$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
if (!ValidateEmail($mailfrom))
{
$error .= "The specified email address is invalid!\n<br>";
}

if (!empty($error))
{
$errorcode = file_get_contents($error_url);
$replace = "##error##";
$errorcode = str_replace($replace, $error, $errorcode);
echo $errorcode;
exit;
}

$internalfields = array ("submit", "reset", "send", "filesize", "formid", "captcha_code", "recaptcha_challenge_field", "recaptcha_response_field", "g-recaptcha-response");
$message .= $eol;
$message .= "IP Address : ";
$message .= $_SERVER['REMOTE_ADDR'];
$message .= $eol;
$logdata = '';
foreach ($_POST as $key => $value)
{
if (!in_array(strtolower($key), $internalfields))
{
if (!is_array($value))
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . $value . $eol;
}
else
{
$message .= ucwords(str_replace("_", " ", $key)) . " : " . implode(",", $value) . $eol;
}
}
}
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($message).$eol;
if (!empty($_FILES))
{
foreach ($_FILES as $key => $value)
{
if ($_FILES[$key]['error'] == 0
:arrow: {
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: '.$_FILES[$key]['type'].'; name='.$_FILES[$key]['name'].$eol;
$body .= 'Content-Transfer-Encoding: base64'.$eol;
$body .= 'Content-Disposition: attachment; filename='.$_FILES[$key]['name'].$eol;
$body .= $eol.chunk_split(base64_encode(file_get_contents($_FILES[$key]['tmp_name']))).$eol;
}
}
}
$body .= '--'.$boundary.'--'.$eol;
if ($mailto != '')
{
mail($mailto, $subject, $body, $header);
}
header('Location: '.$success_url);
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

User avatar
Pablo
 
Posts: 17595
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Syntax error has occurred on php contact

Post by Pablo » Sun Feb 11, 2018 4:51 pm

Are you using the latest update? This issue has already been fixed a couple of months ago.

TrevH
 
 
Posts: 63
Joined: Wed Nov 26, 2014 3:31 pm
Location: UK
Contact:

Re: Syntax error has occurred on php contact

Post by TrevH » Sun Feb 11, 2018 5:29 pm

Hi Pablo, I have got the latest update but didn't realise there was an issue as it had previously worked online when the site was uploaded last year.

I am in the middle of ammending and updating the site (using the very latest version of WB) so... will that automatically fix it when I re-upload the site?

I only plan publish and to upload only once my client's changes have been made in the next couple of days.

Many thanks... :)

User avatar
Pablo
 
Posts: 17595
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Syntax error has occurred on php contact

Post by Pablo » Sun Feb 11, 2018 5:57 pm

will that automatically fix it when I re-upload the site?
\
Yes, if you have the latesr version, it should upload the correct files.

TrevH
 
 
Posts: 63
Joined: Wed Nov 26, 2014 3:31 pm
Location: UK
Contact:

Re: Syntax error has occurred on php contact

Post by TrevH » Sun Feb 11, 2018 6:08 pm

Ok, thank you... :)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest