PHP邮件:附件发送但未赢

时间:2017-11-18 12:27:04

标签: php

邮件运作良好,我在邮箱收到邮件,我也收到了附件,但我无法打开邮件,我真的处于无法使用任何图书馆的情况比如SwiftMailerPHPMailer,所以我需要做这项工作 这是我的代码:

function mail_attachment($to, $subject, $msg, $from, $file) {
        $file_size = filesize($file);
        $handle = fopen($file, "r");
        $content = fread($handle, $file_size);
        fclose($handle);

        $content = chunk_split(base64_encode(file_get_contents($file)));
        $uid = md5(uniqid(time()));

        $eol = PHP_EOL;

        // Basic headers
        $header = "From: Equipe Grifoflex <".$from.">".$eol;
        $header .= "Reply-To: ".$to.$eol;
        $header .= "MIME-Version: 1.0\r\n";
        $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"";

        // Put everything else in $message
        $message = "--".$uid.$eol;
        $message .= "Content-Type: text/html; charset=ISO-8859-1".$eol;
        $message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
        $message .= $msg.$eol;
        $message .= "--".$uid.$eol;
        $message .= "Content-Type: application/pdf; name=\"".$file."\"".$eol;
        $message .= "Content-Transfer-Encoding: base64".$eol;
        $message .= "Content-Disposition: attachment; filename=\"".$file."\"".$eol;
        $message .= $content.$eol;
        $message .= "--".$uid."--";

        return mail($to, $subject, $message, $header);
    }

我在这里缺少什么?

0 个答案:

没有答案