2013-04-23 126 views
0

使用PHP,我在我的Gmail和mailserver id(公司電子郵件ID)上發送電子郵件附件。我在我的電子郵件帳戶中收到了電子郵件,但在我的公司電子郵件ID上收到了我的電子郵件附件中的電子郵件,顯示錯誤(無法正常打開),而在Gmail中則沒有問題。 任何想法或建議? 我在這裏粘貼我的php代碼。任何幫助將不勝感激。電子郵件附件在gmail中正常工作,但在我的郵件服務器上沒有問題

HTML代碼:

<form action="contact.php" method="post" name="form1" enctype="multipart/form-data"> 
    <label for="file">Filename:</label> 
    <input type="file" name="fileAttach" id="file"><br><br> 
    <input type="submit" name="submit" value="Submit" align="right"> 
    </form> 

contact.php:

    <?php 
       if($_POST['submit']) 
       { 

      $strTo = "[email protected], [email protected]"; 
      $strSubject = "Attachment file"; 
      $strMessage = "Attachment"; 
       $txtFormEmail = "[email protected]"; 

      $strSid = md5(uniqid(time())); 

$strHeader = ""; 
$strHeader .= "From: "."<".$txtFormEmail.">\nReply-To: ".$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,$strMessage,$strHeader); 


    } 
    ?> 

回答

0

您可以使用PHP郵件器類帶附件發送郵件。

+1

非常感謝RavK – Ganesh 2015-10-14 10:23:33

相關問題