Witam,
Proszę o pomoc. Skrypt nie działa tak jak trzeba. Zamiast załączać pliki do wiadomości e-mail przychodzi tekst. To jest chyba jakiś problem z kodowaniem.
Próbowałem zmieniać kodowanie, ale dalej to samo.
Oto kod:
<?php
// This will show in the browsers title bar and at the top of the form.
$websitename="Wypełnij formularz zgłoszenia szkody";
// Allowed file types. Please remember to keep the format of this array, add the file extensions you want
// WITHOUT the dot. Please also be aware that certain file types (such as exe) may contain malware.
$allowtypes=array("zip", "rar", "docx", "doc", "jpg", "png", "gif", "odt", "pdf");
// What's your email address? Seperate email addresses with commas for multiple email addresses.
$myemail="getsemane3@gmail.com";
// What priority should the script send the mail? 1 (Highest), 2 (High), 3 (Normal), 4 (Low), 5 (Lowest).
$priority="1";
// Should we allow visitors to attach files? How Many? 0 = Do not allow attachments,
// 1 = allow only 1 file to be attached, 2 = allow two files etc.
$allowattach="4";
// Maximum file size for attachments in KB NOT Bytes for simplicity. MAKE SURE your php.ini can handel it,
// post_max_size, upload_max_filesize, file_uploads, max_execution_time!
// 2048kb = 2MB, 1024kb = 1MB, 512kb = 1/2MB etc..
$max_file_size="1024";
// Maximum file size for all attachments combined in KB. MAKE SURE your php.ini can handel it,
// post_max_size, upload_max_filesize, file_uploads, max_execution_time!
// 2048kb = 2MB, 1024kb = 1MB, 512kb = 1/2MB etc..
$max_file_total="2048";
// Value for the Submit Button
$submitvalue=" Wyślij e-mail ";
// Value for the Reset Button
$resetvalue=" Resetuj ";
// Default subject? This will be sent if the user does not type in a subject
$defaultsubject="Brak tematu";
// Because many requested it, this feature will add a drop down box for the user to select a array of
// subjects that you specify below.
// True = Use this feature, False = do not use this feature
$use_subject_drop=true;
// This is an array of the email subjects the user can pick from. Make sure you keep the format of
// this array or you will get errors.
// Look at <http://novahq.net/forum/showthread.php?t=38718> for examples on how to use this feature.
$subjects=array("Szkoda z OC", "Szkoda z AC");
// This is an array of the email addresses for the array above. There must be an email FOR EACH
// array value specified above. You can have only 1 department if you want.
// YOU MUST HAVE THE SAME AMMOUNT OF $subjects and $emails or this WILL NOT work correctly!
// The emails also must be in order for what you specify above!
// Seperate email addresses by a comma to send an email to multiple addresses.
$emails=array("getsemane3@gmail.com", "getsemane3@gmail.com");
// This is the message that is sent after the email has been sent. You can use html here.
// If you want to redirect users to another page on your website use this:
// <script type=\"text/javascript\">window.location=\"http://www.YOUR_URL.com/page.html\";</script>
$thanksmessage="Dziękujemy, Twój e-mail został poprawnie wysłany. Skontaktujemy się z Tobą najszybciej jak to będzie możliwe.";
/*
//================================================================================
* ! ATTENTION !
//================================================================================
: Don't edit below this line.
*/
// Function to get the extension of the uploaded file.
function get_ext($key) {
return $key;
}
// Function used to attach files to the message
function phattach($file, $name, $boundary) {
$message="--".$boundary."\n";
$message.="Content-Type: application/octet-stream; name=\"".$name."\"\n";
$message.="Content-disposition: attachment; filename=\"".$name."\"\n";
$message.="Content-Transfer-Encoding: base64\n";
$message.="\n";
$message.="$str\n";
$message.="\n";
return $message;
}
//Little bit of security from people forging headers. People are mean sometimes :(
function clean_msg($key) {
"/bcc\:/i",
"/Content\-Type\:/i",
"/Mime\-Type\:/i",
"/cc\:/i",
"/to\:/i"
);
return $key;
}
// Initilize some variables
$error="";
$sent_mail=false;
// When the form is submitted
If($_POST['submit']==true) {
// Check the form for errors
If(trim($yourname)=="") { $error.="Nie wpisałeś imienia i nazwiska!<br />";
}
If(trim($yourphone)=="") { $error.="Nie wpisałeś numeru telefonu!<br />";
}
If(trim($youremail)=="") { $error.="Nie wpisałeś adresu e-mail!<br />";
} Elseif(!preg_match("/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/", $youremail)) { $error.="Niepoprawny adres e-mail.<br />";
}
If(trim($emailsubject)=="") { $emailsubject=$defaultsubject;
}
If(trim($yourmessage)=="") { $error.="Nie wpisałeś wiadomości!<br />";
}
// Verify Attchment info
If($allowattach > 0) {
// Get the total size of all uploaded files
If((array_sum($_FILES['attachment']['size'])) > ($max_file_total*1024
)) {
$error.="Maksymalny rozmiar wszystkich plików wynosi ".$max_file_total."kb<br />";
} Else {
//Loop through each of the files
For($i=0; $i <= $allowattach-1; $i++) {
If($_FILES['attachment']['name'][$i]) {
//Check if the file type uploaded is a valid file type.
If(!in_array(get_ext
($_FILES['attachment']['name'][$i]), $allowtypes)) {
$error.= "Niepoprawne rozszerzenie pliku: ".$_FILES['attachment']['name'][$i]."<br />";
//Check the size of each file
} Elseif(($_FILES['attachment']['size'][$i]) > ($max_file_size*1024)) {
$error.= "Twój załącznik: ".$_FILES['attachment']['name'][$i]." jest za duży.<br />";
} // If in_array
} // If Files
} // For
} // Else array_sum($_FILES['attachment']['size'])
} // If Allowattach
If($error) {
$display_message=$error;
} Else {
$subject_count=count($subjects); $email_count=count($emails);
If($subject_count==$email_count) {
$myemail=$emails[$emailsubject];
$emailsubject=$subjects[$emailsubject];
} // If $subject_count
} // If $use_subject_drop
//Headers
$headers="Return-Path: <".clean_msg($youremail).">\n";
$headers.="From: ".clean_msg($yourname)." <".clean_msg($youremail).">\n".clean_msg($yourphone).">\n";
$headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
$headers.="X-Priority: ".$priority."\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$headers.="This is a multi-part message in MIME format.\n";
//Message
$message = "--".$boundary."\n";
$message.="Content-Type: text/html; charset=\"UTF-8\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n";
$message.="\n";
$message.="\n";
//Add attachments to message
If($allowattach > 0) {
For($i=0; $i <= $allowattach-1; $i++) {
If($_FILES['attachment']['tmp_name'][$i]) {
$message.=phattach($_FILES['attachment']['tmp_name'][$i], $_FILES['attachment']['name'][$i], $boundary);
} //If $_FILES['attachment']['name'][$i]
} //For
} // If
// End the message
$message.="--".$boundary."--\n";
// Send the completed message
If(!mail($myemail, clean_msg
($emailsubject), $message, $headers)) {
Exit("An error has occured, please report this to the website administrator.\n");
} Else {
$sent_mail=true;
}
} // Else
} // $_POST
/*
//================================================================================
* Start the form layout
//================================================================================
:- Use the html below to customize the form.
*/
?>
[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl"> <meta http-equiv="Content-Language" content="pl" /> <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> <title><?php echo $websitename; ?> - Powered By phMailer
</title>
<link rel="stylesheet" type="text/css" href="css/demo.css" /> <link rel="stylesheet" type="text/css" href="css/style1.css" /> <script type="text/javascript" src="js/jssor.slider.js"></script> init_jssor_slider1 = function (containerId) {
var options = {
$AutoPlay: true, //[Optional] Whether to auto play, to enable slideshow, this option must be set to true, default value is false
$SlideDuration: 1000, //[Optional] Specifies default duration (swipe) for slide in milliseconds, default value is 500
$BulletNavigatorOptions: { //[Optional] Options to specify and enable navigator or not
$Class: $JssorBulletNavigator$, //[Required] Class to create navigator instance
$ChanceToShow: 2, //[Required] 0 Never, 1 Mouse Over, 2 Always
$AutoCenter: 1, //[Optional] Auto center navigator in parent container, 0 None, 1 Horizontal, 2 Vertical, 3 Both, default value is 0
$Steps: 1, //[Optional] Steps to go for each navigation request, default value is 1
$Lanes: 1, //[Optional] Specify lanes to arrange items, default value is 1
$SpacingX: 10, //[Optional] Horizontal space between each item in pixel, default value is 0
$SpacingY: 10, //[Optional] Vertical space between each item in pixel, default value is 0
$Orientation: 1 //[Optional] The orientation of the navigator, 1 horizontal, 2 vertical, default value is 1
}
};
var jssor_slider1 = new $JssorSlider$(containerId, options);
}
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> $(function() {
$( "#menu" ).menu();
});
.ui-menu { width: 150px; }
<!-- tutaj były style -->
<script type="text/javascript"> var error="";
e_regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
function Checkit(theform) {
if(theform.yourname.value=="") {
error+="Nie wpisałeś swojego imienia.\n";
}
if(theform.yourphone.value=="") {
error+="Nie wpisałeś numeru telefonu.\n";
}
if(theform.youremail.value=="") {
error+="Nie wpisałeś swojego adresu e-mail.\n";
} else if(!e_regex.test(theform.youremail.value)) {
error+="Niepoprawny adres e-mail.\n";
}
if(theform.yourmessage.value=="") {
error+="Nie wpisałeś wiadomości.\n";
}
if(error) {
alert('**Formularz zwrócił następujące błędy:**\n\n' + error);
error="";
return false;
} else {
return true;
}
}
<?If($display_message) {?>
<div align="center" class="error_message"><b><?=$display_message;?></b></div>
<?}?>
<?If($sent_mail!=true) {?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" name="phmailer" onsubmit="return Checkit(this);">
<table align="center" class="table">
<td width="50%" class="table_body"><input name="yourname" placeholder="Imię i nazwisko" type="text" size="30" value="<?=stripslashes(htmlspecialchars($yourname));?>" />
<span class="error_message">*
</span></td> <td width="50%" class="table_body"><input name="youremail" placeholder="Twój e-mail" type="text" size="30" value="<?=stripslashes(htmlspecialchars($youremail));?>" />
<span class="error_message">*
</span></td>
<td width="50%" class="table_body"><input name="yourphone" placeholder="Twój numer telefonu" type="text" size="30" value="<?=stripslashes(htmlspecialchars($yourphone));?>" />
<span class="error_message">*
</span></td>
<td width="50%" class="table_body">Wybierz rodzaj szkody:
</td> <td width="50%" class="table_body">
<?If($use_subject_drop AND is_array($subjects)) {?>
<select name="emailsubject" size="1"> <?while(list($key,$val)=each($subjects)) {?>
<option value="<?=intval($key);?>">
<?=htmlspecialchars(stripslashes($val));?></option>
<?}?>
<?} Else {?>
<input name="emailsubject" type="text" size="30" value="<?=stripslashes(htmlspecialchars($emailsubject));?>" />
<?}?>
<?For($i=1;$i <= $allowattach; $i++) {?>
<td width="50%" class="table_body">Załącz plik:
</td> <td width="50%" class="table_body"><input name="attachment[]" type="file" /></td> <?}?>
<td colspan="2" width="100%" class="table_body">Twoja wiadomość:
<span class="error_message">*
</span><br /> <textarea name="yourmessage" rows="8" cols="60" placeholder="Ewentualne dodatkowe uwagi lub pytania"><?=stripslashes(htmlspecialchars($yourmessage));?></textarea> <td width="50%" class="table_footer"><input type="hidden" name="submit" value="true" /> <input type="submit" value="<?=$submitvalue;?>" class="btn-1" />
</td><td width="50%" class="table_footer"><input type="reset" value="<?=$resetvalue;?>" class="btn-1" />
<?If($allowattach > 0) {?>
<td width="100%" class="attach_info" colspan="2"> <b>Dopuszczalne rozszerzenia:
</b> <?=implode($allowtypes, ", ");?><br /> <b>Maksymalny rozmiar pliku
</b> <?=$max_file_size?>kb.
<br /> <b>Maksymalny rozmiar plików:
</b> <?=$max_file_total?>kb.
<?}?>
<?} Else {?>
<div align="center" class="thanks_message"><?=$thanksmessage;?></div>
<?}
[/html]
Poradziłem sobie.
Temat do zamknięcia.
BTW. polecam ten skrypt. przy niewielkiej znajomości PHP można go dostosować do własnych potrzeb oraz zmienić CSS.
Tutaj do pobrani:
http://www.phphq.net/scripts.php?script=phMailer#phMailer