nemesis_dex
20-05-2014, 14:27
Witam wszystkich.
Zainstalowałem na stronie komponent Jumi. Ponieważ potrzebuję na stronie zamieścić formularz kontaktowy który przesyłany będzie wraz z załącznikiem na mojego maila. Posługuję się narazie formularzem znalezionym w sieci ale ogólnie gdy wrzucę sam skrypt na serwer to wszystko działa prawidłowo. Problem pojawia się gdy wstawiam go do Jumi, dostaję błąd
Parse error: syntax error, unexpected T_VARIABLE in/home/public_html/strona/components/com_jumi/views/application/view.html.php(77) : eval()'d code on line 137
Oto kod który wklejam do Jumi:
<?php
session_start();
function print_form(){
?>
<p><span class="required">*</span> Required fields</p>
<form method="post" action="<?php echo $_SERVER[’PHP_SELF’];?>" id="uploadform" enctype="multipart/form-data">
<p><label for="namefrom">Name <span class="required">*</span></label>
<input name="namefrom" id="namefrom" type="text" class="field" value="<?= $_SESSION['myForm']['namefrom']; ?>" tabindex="1"/></p>
<p><label for="company">Company</label>
<input name="company" id="company" type="text" class="field" value="<?= $_SESSION['myForm']['company']; ?>" tabindex="2"/></p>
<p><label for="emailfrom">Email <span class="required">*</span></label>
<input name="emailfrom" id="emailfrom" type="text" class="field" value="<?= $_SESSION['myForm']['emailfrom']; ?>" tabindex="3"/></p>
<p><label for="phone">Phone</label>
<input name="phone" id="phone" type="text" class="field" value="<?= $_SESSION['myForm']['phone']; ?>" tabindex="4"/></p>
<p><label for="subject">Subject <span class="required">*</span></label>
<input name="subject" id="subject" type="text" class="field" value="<?= $_SESSION['myForm']['subject']; ?>" tabindex="5"/></p>
<p><label for="comments">Comments <span class="required">*</span></label>
<textarea name="comments" id="comments" rows="7" cols="10" class="field" tabindex="6"><?= $_SESSION['myForm']['comments']; ?></textarea></p>
<p><label for="attachment">File Upload<br />(1 file only, max file size 1024kb. Allowed file formats are .doc, .pdf, .zip, .rar)</label>
<input name="attachment" id="attachment" type="file" tabindex="7">
<p><input type="submit" name="submit" id="submit" value="Send Email!" tabindex="8"/></p>
<p><input type="hidden" name="submitted" value="true" /></p>
</form>
<?php
}
function process_form() {
$to = "moj@mail.com";
$subject = trim($_POST['subject']);
$namefrom = trim($_POST['namefrom']);
$company = trim($_POST['company']);
$phone = trim($_POST['phone']);
$emailfrom = trim($_POST['emailfrom']);
$comments = trim($_POST['comments']);
$allowtypes=array("zip", "rar", "doc", "pdf");
$requirefile="true";
$max_file_size="1024";
$thanksmessage="Your email has been sent, we will respond shortly.";
$errors = array();
if (empty($_POST['namefrom']) ) {
$errors[]='You forgot to enter your name';
}
if (empty($_POST['emailfrom']) ) {
$errors[]='You forgot to enter your email';
} else {
if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['emailfrom'])))) {
$errors[]='Please enter a valid email address';
}
}
if (empty($_POST['subject']) ) {
$errors[]='You forgot to enter a subject';
}
if (empty($_POST['comments']) ) {
$errors[]='You forgot to enter your comments';
}
if($requirefile=="true") {
if($_FILES['attachment']['error']==4) {
$errors[]='You forgot to attach a file';
}
}
if((!empty($_FILES["attachment"])) && ($_FILES['attachment']['error'] == 0)) {
$filename = basename($_FILES['attachment']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
$filesize=$_FILES['attachment']['size'];
$max_bytes=$max_file_size*1024;
if (!in_array($ext, $allowtypes)) {
$errors[]="Invalid extension for your file: <strong>".$filename."</strong>";
} elseif($filesize > $max_bytes) {
$errors[]= "Your file: <strong>".$filename."</strong> is to big. Max file size is ".$max_file_size."kb.";
}
}
if (empty($errors)) {
$fileatt = $_FILES['attachment']['tmp_name'];
$fileatt_type = $_FILES['attachment']['type'];
$fileatt_name = $_FILES['attachment']['name'];
$headers = "From: $emailfrom";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message ="This is a multi-part message in MIME format.\n\n";
$message.="--{$mime_boundary}\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: 7bit\n\n";
$message.="From: ".$namefrom."\n";
$message.="Company: ".$company."\n";
$message.="Phone: ".$phone."\n";
$message.="Comments: ".$comments."\n\n";
if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
foreach ($envs as $env)
$message .= "$env: $_SERVER[$env]\n";
if(!mail($to,$subject,$message,$headers)) {
exit("Mail could not be sent. Sorry! An error has occurred, please report this to the website administrator.\n");
} else {
echo '<div id="formfeedback"><h3>Thank You!</h3><p>'. $thanksmessage .'</p></div>';
unset($_SESSION['myForm']);
print_form();
}
} else {
echo '<div id="formfeedback"><h3>Error!</h3><p>The following error(s) has occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again</p></div>';
print_form();
}
}
$_SESSION['myForm'] = $_POST;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Upload Form</title>
<style type="text/css">
body {font-family: Helvetica, Arial, sans-serif; line-height: 135%; margin-left:50px;}
#uploadform {width: 350px;}
label {display: block;}
input, textarea {width: 90%;}
input#submit {width: auto;}
.required {color: red;}
#formfeedback {background: #fdfbab; padding: 5px;}
</style>
</head>
<body>
<h1>Upload Form</h1>
<div id="uploadform">
<?php
if (isset($_POST['submitted']) && ('true' == $_POST['submitted'])) {
process_form();
} else {
print_form();
}
?>
</div>
</body>
</html>
<?php session_destroy(); ?>
Pierwszy raz posługuję się Jumi jak również nie jestem ekspertem w PHP. Jumi w błędzie odwołuje się do pliku view.html.php. Zakładam że to nie w nim jest problem tylko w tym skrypcie. Czy moglibyście spróbować użyć tego skrpytu u siebie i sprawdzić czy także występuje ten błąd, ewentualnie podpowiedzieć co mogłoby być nie tak.
Z góry dziękuję za pomoc.
Zainstalowałem na stronie komponent Jumi. Ponieważ potrzebuję na stronie zamieścić formularz kontaktowy który przesyłany będzie wraz z załącznikiem na mojego maila. Posługuję się narazie formularzem znalezionym w sieci ale ogólnie gdy wrzucę sam skrypt na serwer to wszystko działa prawidłowo. Problem pojawia się gdy wstawiam go do Jumi, dostaję błąd
Parse error: syntax error, unexpected T_VARIABLE in/home/public_html/strona/components/com_jumi/views/application/view.html.php(77) : eval()'d code on line 137
Oto kod który wklejam do Jumi:
<?php
session_start();
function print_form(){
?>
<p><span class="required">*</span> Required fields</p>
<form method="post" action="<?php echo $_SERVER[’PHP_SELF’];?>" id="uploadform" enctype="multipart/form-data">
<p><label for="namefrom">Name <span class="required">*</span></label>
<input name="namefrom" id="namefrom" type="text" class="field" value="<?= $_SESSION['myForm']['namefrom']; ?>" tabindex="1"/></p>
<p><label for="company">Company</label>
<input name="company" id="company" type="text" class="field" value="<?= $_SESSION['myForm']['company']; ?>" tabindex="2"/></p>
<p><label for="emailfrom">Email <span class="required">*</span></label>
<input name="emailfrom" id="emailfrom" type="text" class="field" value="<?= $_SESSION['myForm']['emailfrom']; ?>" tabindex="3"/></p>
<p><label for="phone">Phone</label>
<input name="phone" id="phone" type="text" class="field" value="<?= $_SESSION['myForm']['phone']; ?>" tabindex="4"/></p>
<p><label for="subject">Subject <span class="required">*</span></label>
<input name="subject" id="subject" type="text" class="field" value="<?= $_SESSION['myForm']['subject']; ?>" tabindex="5"/></p>
<p><label for="comments">Comments <span class="required">*</span></label>
<textarea name="comments" id="comments" rows="7" cols="10" class="field" tabindex="6"><?= $_SESSION['myForm']['comments']; ?></textarea></p>
<p><label for="attachment">File Upload<br />(1 file only, max file size 1024kb. Allowed file formats are .doc, .pdf, .zip, .rar)</label>
<input name="attachment" id="attachment" type="file" tabindex="7">
<p><input type="submit" name="submit" id="submit" value="Send Email!" tabindex="8"/></p>
<p><input type="hidden" name="submitted" value="true" /></p>
</form>
<?php
}
function process_form() {
$to = "moj@mail.com";
$subject = trim($_POST['subject']);
$namefrom = trim($_POST['namefrom']);
$company = trim($_POST['company']);
$phone = trim($_POST['phone']);
$emailfrom = trim($_POST['emailfrom']);
$comments = trim($_POST['comments']);
$allowtypes=array("zip", "rar", "doc", "pdf");
$requirefile="true";
$max_file_size="1024";
$thanksmessage="Your email has been sent, we will respond shortly.";
$errors = array();
if (empty($_POST['namefrom']) ) {
$errors[]='You forgot to enter your name';
}
if (empty($_POST['emailfrom']) ) {
$errors[]='You forgot to enter your email';
} else {
if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['emailfrom'])))) {
$errors[]='Please enter a valid email address';
}
}
if (empty($_POST['subject']) ) {
$errors[]='You forgot to enter a subject';
}
if (empty($_POST['comments']) ) {
$errors[]='You forgot to enter your comments';
}
if($requirefile=="true") {
if($_FILES['attachment']['error']==4) {
$errors[]='You forgot to attach a file';
}
}
if((!empty($_FILES["attachment"])) && ($_FILES['attachment']['error'] == 0)) {
$filename = basename($_FILES['attachment']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
$filesize=$_FILES['attachment']['size'];
$max_bytes=$max_file_size*1024;
if (!in_array($ext, $allowtypes)) {
$errors[]="Invalid extension for your file: <strong>".$filename."</strong>";
} elseif($filesize > $max_bytes) {
$errors[]= "Your file: <strong>".$filename."</strong> is to big. Max file size is ".$max_file_size."kb.";
}
}
if (empty($errors)) {
$fileatt = $_FILES['attachment']['tmp_name'];
$fileatt_type = $_FILES['attachment']['type'];
$fileatt_name = $_FILES['attachment']['name'];
$headers = "From: $emailfrom";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message ="This is a multi-part message in MIME format.\n\n";
$message.="--{$mime_boundary}\n";
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message.="Content-Transfer-Encoding: 7bit\n\n";
$message.="From: ".$namefrom."\n";
$message.="Company: ".$company."\n";
$message.="Phone: ".$phone."\n";
$message.="Comments: ".$comments."\n\n";
if (is_uploaded_file($fileatt)) {
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
$envs = array("HTTP_USER_AGENT", "REMOTE_ADDR", "REMOTE_HOST");
foreach ($envs as $env)
$message .= "$env: $_SERVER[$env]\n";
if(!mail($to,$subject,$message,$headers)) {
exit("Mail could not be sent. Sorry! An error has occurred, please report this to the website administrator.\n");
} else {
echo '<div id="formfeedback"><h3>Thank You!</h3><p>'. $thanksmessage .'</p></div>';
unset($_SESSION['myForm']);
print_form();
}
} else {
echo '<div id="formfeedback"><h3>Error!</h3><p>The following error(s) has occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again</p></div>';
print_form();
}
}
$_SESSION['myForm'] = $_POST;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Upload Form</title>
<style type="text/css">
body {font-family: Helvetica, Arial, sans-serif; line-height: 135%; margin-left:50px;}
#uploadform {width: 350px;}
label {display: block;}
input, textarea {width: 90%;}
input#submit {width: auto;}
.required {color: red;}
#formfeedback {background: #fdfbab; padding: 5px;}
</style>
</head>
<body>
<h1>Upload Form</h1>
<div id="uploadform">
<?php
if (isset($_POST['submitted']) && ('true' == $_POST['submitted'])) {
process_form();
} else {
print_form();
}
?>
</div>
</body>
</html>
<?php session_destroy(); ?>
Pierwszy raz posługuję się Jumi jak również nie jestem ekspertem w PHP. Jumi w błędzie odwołuje się do pliku view.html.php. Zakładam że to nie w nim jest problem tylko w tym skrypcie. Czy moglibyście spróbować użyć tego skrpytu u siebie i sprawdzić czy także występuje ten błąd, ewentualnie podpowiedzieć co mogłoby być nie tak.
Z góry dziękuję za pomoc.