2016-05-26 7 views
1

PHPMailerに迷惑をかけています。PHP複数のファイルをアップロードし、PHPMailer経由でメールにインラインで添付します。

基本的には、複数の画像をアップロードして自分のサーバー上のフォルダに保存できるフォームがあります。その後、PHPMailer経由でメールの下にインラインで画像が添付されたメールを送信する必要があります。私はそれがインラインとして最初に画像を配置するが、画像の残りの部分は表示されません取得することができます

..

いくつかのコード:

require '../PHPMailer/PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

if(count($_FILES['upload']['name']) > 0){ 
    //Loop through each file 
    for($i=0; $i<count($_FILES['upload']['name']); $i++) { 
     //Get the temp file path 
     $tmpFilePath = $_FILES['upload']['tmp_name'][$i]; 

     //Make sure we have a filepath 
     if($tmpFilePath != ""){ 

      //save the filename 
      $shortname = $_FILES['upload']['name'][$i]; 


      //save the url and the file 
      $filePath = "../reports/".$id."/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i]; 

      //Upload the file into the temp dir 
      if(move_uploaded_file($tmpFilePath, $filePath)) { 

       $files[] = $shortname; 
       //insert into db 
       //use $shortname for the filename 
       //use $filePath for the relative url to the file 


      $mail->AddEmbeddedImage($filePath, $shortname, $shortname); 
      $atts = '<img src="cid:'.$shortname.'">'; 


      } 
      } 
    } 
} 
$mail->Body .= $atts; 

答えて

0

ソリューション:

$dir2 = opendir('../reports/'.$id); // Open the directory containing the uploaded files. 

$files = array(); 
while ($files[] = readdir($dir2)); 
rsort($files); 
closedir($dir2); 

foreach ($files as $file) { 


     if ($file != "." && $file != ".." && $file != 'resources'){ 
     $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file); 
     $url = '../reports/'.$id.'/'.$file; 
     $mail->AddEmbeddedImage($url, $withoutExt); 
     $mail->Body .= '<img src="cid:'.$withoutExt.'">'; 
     } 

} 
関連する問題