MIME 文件附件打不开

MIME file attachment is not opening

我的密码是

<?php

require_once "Mail.php"; // PEAR Mail package
require_once ('Mail/mime.php'); // PEAR Mail_Mime packge 

 $from = "<meenu.spiralbean@gmail.com>";
 $to = "<meenu.spiralbean@gmail.com>";
 $subject = "Hi!";


$host = "ssl://smtp.googlemail.com";
$port = "465";
$username = "example@gmail.com";
$password = "example";

$smtp = Mail::factory('smtp',
   array ('host' => $host,
   'port' => $port,
  'auth' => true,
  'username' => $username,
  'password' => $password));


$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);


 // attachment
 $file = '/var/www/html/formsubmit/TodoList/upload/abc.pdf';
 $crlf = "n";
 $text="Helllooooo";
 $html = "<html> <head> <title>Mail test</title> </head>  <body>something</body></html>";

$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
if($mime->addAttachment($file))
{
   echo "Success";
}
else 

{
    echo "Failed";
}


$body = $mime->get();
$headers = $mime->headers($headers);


$mail = $smtp->send($to, $headers, $body);


if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
 } else {
 echo("<p>Message successfully sent!</p>");
}
?>

附件下载后打不开

邮件进入收件箱,附件也是 there.But 附件看起来像 txt file.but 我实际上附加了一个 pdf 文件。我使用了SMTP邮件和MIME邮件功能。

请帮助我。

邮件中的相关代码为:

Content-Transfer-Encoding: base64
Content-Type: application/octet-stream;
 name=abc.pdf
Content-Disposition: attachment;
 filename=abc.pdf;
 size=4997278

内容类型是通用的;尝试使用 application/pdf 作为 addAttachment().

的第二个参数

此外,永远不要在任何地方 post 您的真实邮件地址和密码。