Ileti formumla birden fazla ek gönderebilmek istiyorum, ekleri gönderdiğimde [email protected] adresinden dizi eki alıyorum. Bunların ayrı ekler olarak nasıl yapıldığını bilmiyorum.Php form ekleri dosya yerine dizi olarak gönderiliyor
HTML kodunu
<form id="contact-form" action="contact.php" method="post" enctype="multipart/form-data">
<div class="row">
<div>
<div class="form-group">
<label for="name">
Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required />
</div>
<div class="form-group">
<label for="email">
Email Address</label>
<div class="input-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required /></div>
</div>
<div class="form-group">
<label for="subject">
Subject</label>
<select id="subject" name="subject" class="form-control" required>
<option value="na" selected="careers">Choose One:</option>
<option value="careers">Careers</option>
<option value="general">General</option>
</select>
</div>
<div class="form-group">
<label for ="attach">
Attachments</label>
<input type="file" class="form-control" name="newupload[]" id="newupload" />
<input type="file" class="form-control" name="newupload[]" id="newupload" />
<input type="file" class="form-control" name="newupload[]" id="newupload" />
</div>
</div>
<div class="form-group">
<label for="name">
Message</label>
<textarea name="message" id="message" class="form-control" rows="7" cols="20" required
placeholder="Message"></textarea>
</div>
<button type="submit" name="submit" id="btnContactUs">
Send Message</button>
</div>
</form>
PHP
<?php
if($_POST && isset($_FILES['newupload'])) {
$name=$_POST["name"];
$email=$_POST["email"];
$subject=$_POST["subject"];
$newupload=$_POST["newupload"];
$message=$_POST["message"];
$recipient_email = '[email protected]';
//get file details we need
$file_tmp_name = $_FILES['newupload']['tmp_name'];
$file_name = $_FILES['newupload']['name'];
$file_size = $_FILES['newupload']['size'];
$file_type = $_FILES['newupload']['type'];
$file_error = $_FILES['newupload']['error'];
$user_email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
//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));
$boundary = md5("sanwebe");
//header
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " .$email. "\n";
$headers .= "Subject: " .$subject. "\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('Name: ' .$name."\n".
'Email: ' .$email."\n".
'Subject: ' .$subject."\n".
'Message: ' .$message."\r\n"));
//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);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
}
?>
bir değişiklik yaptım olduğunu. –
Teşekkür ederim Mauricio! Kusursuz çalışıyor! 10/10 – dmm503
Cevabımı doğru olarak işaretle, lütfen –