2015-01-06 206 views
1

所以基本上我想要一個可以發送帶有一個或多個圖片的郵件的電子郵件系統,我現在的問題是,當我上傳時,讓我們說4張圖片,表單向我發送4封電子郵件一次只能顯示一張相同的文字。我希望它們全部作爲4個附件添加到1封電子郵件中,而不是附加到4封電子郵件。電子郵件表單根據附件發送多個郵件

這裏是我的HTML:

<form id="upload" method="post" action="upload.php"> 
      <div id="drop"> 
       Onderwerp<br> 
       <input name="txtSubject" type="text" id="txtSubject" /><br> 

       Omschrijving<br> 
       <textarea name="txtDescription" cols="30" rows="4" id="txtDescription"></textarea><br> 

       Voeg afbeeldingen toe 
       <input type="file" name="fileAttach" multiple accept="image/*;capture=camera" /> 

       <input type="submit" name="Submit" value="Send"> 
      </div> 

      <ul> 
       <!-- The file uploads will be shown here --> 
      </ul> 

     </form> 

,這裏是我的PHP:

<? 
    $strTo = "[email protected]"; 
    $strSubject = $_POST["txtSubject"]; 
    $strMessage = nl2br($_POST["txtDescription"]); 

    //*** Uniqid Session ***// 
    $strSid = md5(uniqid(time())); 

    $strHeader = ""; 
    $strHeader .= "From: ".$_POST["txtFormName"]."<".$_POST["txtFormEmail"].">\nReply-To: ".$_POST["txtFormEmail"].""; 

    $strHeader .= "MIME-Version: 1.0\n"; 
    $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n"; 
    $strHeader .= "This is a multi-part message in MIME format.\n"; 

    $strHeader .= "--".$strSid."\n"; 
    $strHeader .= "Content-type: text/html; charset=utf-8\n"; 
    $strHeader .= "Content-Transfer-Encoding: 7bit\n\n"; 
    $strHeader .= $strMessage."\n\n"; 

    //*** Attachment ***// 
    if($_FILES["fileAttach"]["name"] != "") 
    { 
     $strFilesName = $_FILES["fileAttach"]["name"]; 
     $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
     $strHeader .= "--".$strSid."\n"; 
     $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
     $strHeader .= "Content-Transfer-Encoding: base64\n"; 
     $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n"; 
     $strHeader .= $strContent."\n\n"; 
    } 


    $flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error // 

    if($flgSend) 
    { 
     echo "Mail send completed."; 
    } 
    else 
    { 
     echo "Cannot send mail."; 
    } 
?> 

我不是用PHP很大,我花了一個多圖片上傳,並試圖把它做成一個郵寄表格,除了多個電子郵件發送部分外,其他工作。

任何幫助,非常感謝! :)

+0

使用。快捷的郵件 – donald123

回答

0

嘗試類似:for循環,包括附件...更好的方式使用郵件類如

for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++) 
{ 
if($_FILES["fileAttach"]["name"][$i] != "") 
{ 
$strFilesName = $_FILES["fileAttach"]["name"][$i]; 
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"][$i]))); 
$strHeader .= "--".$strSid."\n"; 
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
$strHeader .= "Content-Transfer-Encoding: base64\n"; 
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n"; 
$strHeader .= $strContent."\n\n"; 
} 
}