php - MIME file attachment is not opening -


my code is

<?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 sent!</p>"); } ?> 

the attachment unable open after downloading it.

mail coming in inbox , attachment there.but attachment seems txt file.but attaching pdf file. used smtp mail , mime mail functions.

pls me.

the relevant code in mail is:

content-transfer-encoding: base64 content-type: application/octet-stream;  name=abc.pdf content-disposition: attachment;  filename=abc.pdf;  size=4997278 

the content type generic one; try use application/pdf second parameter addattachment().


also, never post real mail address , password anywhere.


Comments