dongshanni1611 2019-06-18 14:01
浏览 50

当通过gmail api php代码发送邮件时,附件在Apple邮件客户端中被复制

I am using the Gmail Api code in php to send mails to clients. The mail contains multiple attachments and all works good except for the clients who are using the apple mail app. They see the duplicated attachments. That is if the mail has 4 different attachments, all they see in apple mail app is 4 same duplicated attachments. Please see my code below.

$objGMail = new Google_Service_Gmail($this->googleauth->client);
$strRawMessage = "";
$boundary = uniqid(rand(), true);
$subjectCharset = $charset = 'utf-8';

$strRawMessage .= 'To: ' .$toEmailsName . " <" . $ToEmail . ">" . "
"; 
$strRawMessage .= 'Cc: ' .$ccEmailsName . " <" . $CcEmail . ">" . "
";  
$strRawMessage .= 'Bcc: ' .$BccEmailsName . " <" . $BccEmail . ">" . "
";
$strRawMessage .= 'From: '.$fromName . " <" . $fromEmail . ">" . "
";   
$strRawMessage .= 'Subject: =?' . $subjectCharset . '?B?' . base64_encode($EmailSubject) . "?=
";         
$strRawMessage .= 'MIME-Version: 1.0' . "
";  
$finfo = finfo_open(FILEINFO_MIME_TYPE); 

//Attachments
if (isset($post['UploadedFileName'])) {
    for ($i = 0; $i < count($post['UploadedFileName']); $i++) {
        if ($post['UploadedFileName'][$i] <> "") {                                                                 
            $filePath = './attachments/' . $post['UploadedFileName'][$i];
            $mimeType = finfo_file($finfo, $filePath);                   
            $fileName = $post['UploadedFileName'][$i];                  
            $fileData = chunk_split(base64_encode(file_get_contents($filePath)), 76, "
") . "
";       

            $strRawMessage .= 'Content-type: Multipart/Mixed; boundary="' . $boundary . '"' . "
";                                                                                                  
            $strRawMessage .= "
--{$boundary}
";
            $strRawMessage .= 'Content-Type: '. $mimeType .'; name="'. $fileName .'";' . "
";            
            $strRawMessage .= 'Content-ID: <' . $fromEmail . '>' . "
";            
            $strRawMessage .= 'Content-Description: ' . $fileName . ';' . "
";
            $strRawMessage .= 'Content-Disposition: attachment; filename="' . $fileName . '"; size=' . filesize($filePath). ';' . "
";
            $strRawMessage .= 'Content-Transfer-Encoding: base64' . "

";               
            $strRawMessage .=  $fileData;               
            $strRawMessage .= "--{$boundary}
";                                                                                                 
        }
    }
}

$strRawMessage .= 'Content-Type: text/html; charset=' . $charset . "
";
$strRawMessage .= 'Content-Transfer-Encoding: quoted-printable' . "

";
$strRawMessage .= $EmailBody . "
";
$mime = rtrim(strtr(base64_encode($strRawMessage), '+/', '-_'), '=');
$msg = new Google_Service_Gmail_Message();
$msg->setRaw($mime);
$objSentMsg = $objGMail->users_messages->send("me", $msg);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大