Witam,
mam problem z kodem dotyczącym formularza oraz wysyłania maila z załącznikiem:
Właściwie problem zaczyna się już na samym początku.. nie wiem dlaczego wtyczka validate nie chce przeprowadzić walidacji...
Wpierw formularz:
<form method="post" name="formularz-aplikacyjny" action="mail.php" enctype="multipart/form-data" id="mail">
<input type="text" name="name" id="name" type="text" class="required" title="Wpisz swoje imię i nazwisko"></div><br>
<input type="text" name="email" type='text' class="required" id="email" title="Wpisz swój adres email"></div><br>
<textarea name="message" rows='5' cols='48' maxrows='7' class="required" id="message" title="Wpisz treść listu motywacyjnego" ></textarea></div><br>
<input type="file" name="uploaded_file" title="<h3>Wybierz plik CV do przesłania
</h3>" class="required" id="file">
</div><br>
<input type="submit" value="Prześlij" id="submitbutton">
<h2>Wysyłamy maila.....
</h2> <h2>Twój e-mail został wysłany!
</h2>
Tutaj wtyczka validate i kod umiszczony w $(document).ready(function() {});
Kod
$('#mail').validate({
rules: {
email: {
required: true,
email: true
},
name: {
required: true
},
message: {
required: true,
rangelength:[50,300]
}
}, //koniec literału obiektowego rules
messages: {
email: {
required: "<h3>Podaj adres e-mail.</h3>",
email: "<h3>To nie jest prawidłowy <br>adres e-mail.</h3>"
},
name: {
required: "<h3>Podaj swoje imię i nazwisko.</h3>"
},
message: {
required: "<h3>Wpisz treść listu motywacyjnego.</h3>",
rangelength: "<h3>List motywacyjny powinien mieć od 50 do 300 znaków.</h3>"
}
},
submitHandler: function() {
var thisForm = $('form');
$('form').fadeOut(function(){
//Display the "loading" message
$("#loading").fadeIn(function(){
//Post the form to the send script
$.ajax({
type: 'POST',
url: thisForm.attr("action"),
data: thisForm.serialize(),
//Wait for a successful response
success: function(data){
//Hide the "loading" message
$("#loading").fadeOut(function(){
//Display the "success" message
$("#success").text(data).fadeIn();
}
});
});
});
}
}); // koniec funkcji validate
oraz kod php który wogóle nie wysyła mi żadnych informacji z pól formularza oraz błędnie wysyła załącznik... czy mógłby mi ktoś pomoc ?
<?php
if(isset($_FILES) && (bool
) $_FILES) {
$allowedExtensions = array("pdf","doc","docx","txt");
foreach($_FILES as $name=>$file) {
$file_name = $file['name'];
$temp_name = $file['tmp_name'];
$file_type = $file['type'];
$ext = $path_parts['extension'];
if(!in_array($ext,$allowedExtensions)) { die("File $file_name has the extensions $ext which is not allowed"); }
}
// email fields: to, from, subject, and so on
$to = "dawid.zaik@gmail.com";
$from = $_POST['email'];
$subject ="Formularz aplikacyjny";
$message = $_POST['message'];
$imie = $_POST['name'];
$headers = "From: $name $from";
// boundary
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// headers for attachment
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
// multipart boundary
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
// preparing attachments
for($x=0;$x<count($files);$x++){
$file = fopen($files[$x],"rb"); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
// send
mail($to, $subject, $message, $headers); echo "Twój e-mail został wysłany! Dziękujemy za kontakt."; }
?>