我不能附加多个文件。如果我附加的文件多于一个文件,电子邮件总是发送 1 个文件附件,但我的附件多于一个文件。
if(isset($_POST['upload'])){
include('config.php');
include_once('Mail.php');
include_once('Mail/mime.php');
$allowed_ext = array('jpg','bmp','gif','png','jpeg');
for($i=0; $i<count($_FILES['file']['name']); $i++) {
$file_name = $_FILES['file']['name'][$i];
$file_ext = strtolower(end(explode('.', $file_name)));
$file_size = $_FILES['file']['size'][$i];
$file_tmp = $_FILES['file']['tmp_name'][$i];
$username = $_POST['username'];
$judul = $_POST['judul'];
$berita = $_POST['berita'];
$max_size = 25*1024*1024;
$tanggal_kirim = date("Y-m-d H:i:s");
if(in_array($file_ext, $allowed_ext) === true){
if($file_size <= $max_size){
$file_path = "foto/". $_FILES['file']['name'][$i];
move_uploaded_file($file_tmp, "$file_path");}
mysql_query("INSERT INTO foto VALUES('', '$username', '$tanggal_kirim', '$judul', '$berita','0')");
}
$query = "SELECT email,password_email FROM users where username='$username'";
$sql = mysql_query($query);
$data = mysql_fetch_assoc($sql);
$subject = $judul;
$body = $berita;
//mail($to, $subject, $body,$headers);
//email tujuan
$to = "babagusandrian@gmail.com";
$host = "ssl://smtp.gmail.com";
$port = "465";
$from = $useremail = $data['email'];
$password = $data['password_email'];
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
$namafile[$i] = "$file_path/$file_name";
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($body);
$mime->addAttachment($namafile[$i],'image/jpg');
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array('host' => $host,
'port' => $port, 'auth' => true,
'username' => $useremail, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if($mail){
echo '<div class="ok">SUCCESS: Foto terkirim!</div>';
}else{
echo '<div class="error">ERROR: Foto gagal dikirim!</div>';
}
}
}
我的代码有什么问题?请帮我。给我解决....谢谢你.....对不起我的英语,我来自印度尼西亚。所以只是很少说英语。对不起……