php kontakt form fejl
hej jeg har denne her kode hvor jeg får denne fejlden kommer hvis man ikke har uploadet en fil med når man sender .. så har jeg bare sat den til 4 i erroren så den kunne passerede eller skriver den error uploda og kan slet ikke komme igennem... hvordan kan jeg fjerne denne fejl?+ på forhånd tak
Warning: fopen(): Filename cannot be empty in /customers/c/a/c/.nu/httpd.www/bestilform.php on line 55 Warning: fread() expects parameter 1 to be resource, boolean given in /customers/c/a/c//httpd.www/bestilform.php on line 56 Warning: fclose() expects parameter 1 to be resource, boolean given in /customers/c/a/c//httpd.www/bestilform.php on line 57
(div)
<html>
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/bootstrap-datepicker.min.css" rel="stylesheet" type="text/css"/>
<link href="assets/css/style.css" rel="stylesheet" type="text/css"/>
<div class="container">
<form class="well form-horizontal" action="haandvaerker-tilbud.php" method="post" id="contact_form" enctype="multipart/form-data">
<fieldset>
<h2></h2>
<?php
if ($_POST['email']) {
$from_email = 'info@info.dk'; //sender email
$recipient_email = 'modtagerensmailmail@mail.dk'; //recipient email
$subject = 'Henvendelse os'; //subject of email
$message = 'Besked fra os.nu,' . "\n\n\n"; //message body
$message .= 'Navn: ' . $_POST['name'] . "\n";
$message .= 'E-mail: ' . $_POST['email'] . "\n";
$message .= 'Telefon nr: ' . $_POST['isd'] . '-' . $_POST['phone'] . "\n";
$message .= 'Dato: ' . $_POST['date'] . "\n";
$message .= 'Vedrøre: ' . $_POST['state'] . "\n";
$message .= 'Besked: ' . $_POST['comment'] . "\n\n\n\n";
$message .= 'Denne E-mail er sendt fra fra os';
$boundary = md5("sanwebe");
//header
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From:".$from_email."\r\n";
$headers .= "Reply-To: ".$user_email."" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text
$body = "--$boundary\r\n";
$body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode($message));
if(isset($_FILES['my_file'])){
//get file details we need
$file_tmp_name = $_FILES['my_file']['tmp_name'];
$file_name = $_FILES['my_file']['name'];
$file_size = $_FILES['my_file']['size'];
$file_type = $_FILES['my_file']['type'];
$file_error = $_FILES['my_file']['error'];
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
if($file_error>4)
{
die('upload error');
}
//read from the uploaded file & base64_encode content for the mail
$handle = fopen($file_tmp_name, "r");
$content = fread($handle, $file_size);
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$body .= $encoded_content;
}
$sentMail = @mail($recipient_email, $subject, $body, $headers);
if ($sentMail) //output success or failure messages
{
?>
<div class="alert alert-success" role="alert">Success <i
class="glyphicon glyphicon-thumbs-up"></i> Tak for din henvendelse! Vi har modtaget din besked og vender tilbage hurtigst muligt.
</div>
<?php
} else {
?>
<div class="alert alert-error" role="alert">Der opstod en teknisk fejl. Vær venligt at skrive en e-mail eller ringe til os i stedet for.
</div>
<?php
}
}
?>
<div class="form-group">
<label class="col-md-4 control-label">Dit Navn:</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="name" placeholder="Dit Navn" class="form-control" type="text"
required="required">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">Din E-mail:</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input name="email" placeholder="Din E-mail" class="form-control" type="email"
required="required">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">Dit telefon nr:</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input name="isd" placeholder="(+45)" class="form-control" type="tel" required="required"
id="ph1">
<input name="phone" placeholder="555-1212" class="form-control ph" type="tel"
required="required" id="ph2">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">Dato:</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group date" data-provide="datepicker">
<div class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</div>
<input type="text" class="form-control" required="required" name="date">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">Vedhæft fil</label>
<div class="col-md-4 inputGroupContainer" style="display:flex;">
<input id="uploadFile" class="form-control" placeholder="Choose File" disabled="disabled"/>
<div class="fileUpload btn btn-primary ">
<span class="rightbrowse">Hent fil</span>
<input id="uploadBtn" type="file" class="upload" name="my_file"/>
</div>
</div>
</div>
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label">Vedrøre:</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select name="state" class="form-control selectpicker">
<option value="Håndværkertilbud">Håndværkertilbud</option>
<option value="Jobansøgning">Jobansøgning</option>
<option value="Generel forespørgsel">Generel forespørgsel</option>
</select>
</div>
</div>
</div>
<!-- Text area -->
<div class="form-group">
<label class="col-md-4 control-label">Besked:</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea class="form-control" name="comment" placeholder=" " required="required"></textarea>
</div>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<button type="submit" class="btn btn-primary">Send <span class="glyphicon glyphicon-send"></span>
</button>
</div>
</div>
<p>OBS!</i> Dine oplysninger videregives ikke til 3. part.</p>
</fieldset>
</form>
</div>
</div><!-- /.container -->
<script type="text/javascript" src="assets/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="assets/js/placeholder.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<!--<script type="text/javascript" src="assets/js/form-validation.js"></script>-->
<script src="assets/js/bootstrap-datepicker.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$('.date').datepicker({
autoclose: true
});
});
</script>
</html>
(/div)