0

使用 PHP,我在我的 gmail 和邮件服务器 ID(公司电子邮件 ID)上发送电子邮件附件。我在我的两个电子邮件帐户中都收到了电子邮件,但是在我的公司电子邮件 ID 上,我的电子邮件附件显示错误(它无法正确打开),而在 gmail 中它很好。有什么想法或建议吗??我在这里粘贴我的 php 代码。任何帮助将不胜感激。

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>

联系方式.php:

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

           $strTo = "mymail@company.com, mymail@gmail.com";
            $strSubject = "Attachment file";
            $strMessage = "Attachment";
                $txtFormEmail = "mymail@gmail.com";

           $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); 


  }
  ?>
4

1 回答 1

0

您可以使用 PHP Mailer Class 发送带有附件的邮件。

于 2015-10-14T10:22:41.147 回答