subha Posted June 7, 2009 Share Posted June 7, 2009 i use phpmailer class. To attach a file i used AddAttachment function. I attach more than one file.. But the first attachment only send to email. Others are not sent.. I don't know how to fix this bug. Please help me guys. Link to comment https://forums.phpfreaks.com/topic/161248-how-to-attach-more-than-one-file-using-phpmailer/ Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 http://sourceforge.net/forum/forum.php?thread_id=3176187&forum_id=81620 3rd message down: http://sourceforge.net/forum/message.php?msg_id=7090445 Link to comment https://forums.phpfreaks.com/topic/161248-how-to-attach-more-than-one-file-using-phpmailer/#findComment-850873 Share on other sites More sharing options...
subha Posted June 7, 2009 Author Share Posted June 7, 2009 ya.. i used that.. it uploads all the file. but it attaches the first file only.. <?php require("phpmailer/class.phpmailer.php"); //Variables Declaration $name = "the Submitter"; $email_subject = "Images Attachment"; $Email_msg ="A visitor submitted the following :\n"; $Email_to = "[email protected]"; // the one that recieves the email $email_from = "[email protected]"; $dir = "uploads/$filename"; chmod("uploads",0777); $attachments = array(); // checkType(); // //------Check TYPE------\\ function checkType() { while(list($key,$value) = each($_FILES[images][type])){ strtolower($value); if($value != "image/jpeg" AND $value != "image/pjpeg" AND $value != "") { exit('Sorry , current format is <b>'.($value).'</b> ,only Jpeg or jpg are allowed.') ; } } // checkSize(); // } //-------END OF Check TYPE--------\\ // //---CheckSizeFunction ---\\ function checkSize(){ while(list($key,$value) = each($_FILES[images])) { $maxSize = 5000000; if(!empty($value)){ if ($value > $maxSize) { echo"Sorry this is a very big file .. max file size is $maxSize Bytes = 5 MB"; exit(); } else { $result = "File size is ok !<br>"; // } // } // } uploadFile(); // } //-------END OF Check Size--------\\ // //==============upload File Function============\\ // function uploadFile() { global $attachments; while(list($key,$value) = each($_FILES[images][name])) { // if(!empty($value)) { $filename = $value; //the Array will be used later to attach the files and then remove them from server ! array_push($attachments, $filename); $dir = "uploads/".$filename; //chmod("uploads",0777); $success = move_uploaded_file($_FILES[images][tmp_name][$key], $dir); } // } // if ($success) { echo " Files Uploaded Successfully<BR>"; SendIt(); // }else { exit("Sorry the server was unable to upload the files..."); } // } // //==== PHP Mailer With Attachment Func ====\\ // function SendIt() { // global $attachments,$name,$Email_to,$Email_msg,$email_subject,$email_from; // $mail = new PHPMailer(); //$mail->IsSMTP();// send via SMTP $mail->IsMail(); $mail->Host = "localhost"; // SMTP servers //$mail->SMTPAuth = false; // turn on/off SMTP authentication $mail->From = $email_from; $mail->FromName = $name; $mail->AddAddress($Email_to); $mail->AddReplyTo($email_from); $mail->WordWrap = 50;// set word wrap //now Attach all files submitted foreach($attachments as $key => $value) { //loop the Attachments to be added ... $mail->AddAttachment("uploads"."/".$value); } $mail->Body = $Email_msg."Name : ".$name."\n"; // $mail->IsHTML(true);// send as HTML $mail->Subject = $email_subject; if(!$mail->Send()) { echo "Message was not sent <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } // echo "Message has been sent"; // after mail is sent with attachments , delete the images on server ... //oreach($attachments as $key => $value) {//remove the uploaded files .. //unlink("uploads"."/".$value); } // // ?> Link to comment https://forums.phpfreaks.com/topic/161248-how-to-attach-more-than-one-file-using-phpmailer/#findComment-851008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.