Hi
i have an email script in php send emails to client automatically with attachement ..the problem
with gmail i can get the pdf attachment no problem..
with outlook there ie a problem that the attachement is not openning said pdf not readable
with thunderbird the attachment is empty size 0
any help please

Could you post your code?

Of the top of my head, I would guess that the headers for the email attachment are somehow incorrect. For instance, if you pass an invalid Content-Length header, or don't pass it at all, it is entirely possible that some email clients won't download the file correctly, or just assume it is empty.

`

$output = ob_get_clean();
file_put_contents('reported.html',$output);
//echo $output;
//mail($email,"Daily Report not reported","<html><body>$output</body></html>","MIME-Version: 1.0\r\nContent-type: text/html; /charset=iso-8859-1\r\n"); 
require(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
$font="<page style='font-family: Arial'>...</page>";

try {
        $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8',5);// you can use the default parms


                $html2pdf->pdf->SetDisplayMode('fullpage'); 
                $html2pdf->writeHTML($output);
                $html2pdf->Output('reported.pdf','F');

}
    catch(HTML2PDF_exception $e) { 
echo $e; 
}
echo '<br>';
//-----------------------------------------------
     //DECLARE LES VARIABLES
     //-----------------------------------------------

     $email_expediteur='info@campion.ie';
     $email_reply='info@campion.ie';
     $message_texte=' ';

     $message_html='<html>
     <head>
     <title>Not Reported Units</title>
     </head>
    <br>
     <body>Units not reported </body>

     </html>';

     //-----------------------------------------------
     //GENERE LA FRONTIERE DU MAIL ENTRE TEXTE ET HTML
     //-----------------------------------------------

     $frontiere = '-----=' . md5(uniqid(mt_rand()));

     //-----------------------------------------------
     //HEADERS DU MAIL
     //-----------------------------------------------

     $headers = 'From :<'.$email_expediteur.'>'."\n";
     $headers .= 'Return-Path: <'.$email_reply.'>'."\n";
     $headers .= 'MIME-Version: 1.0'."\n";
     $headers .= 'Content-Type: multipart/mixed; boundary="'.$frontiere.'"';

     //-----------------------------------------------
     //MESSAGE TEXTE
     //-----------------------------------------------
     $message = 'This is a multi-part message in MIME format.'."\n\n";
     $message .= '--'.$frontiere."\n";
     $message .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";
     $message .= 'Content-Transfer-Encoding: 8bit'."\n\n";
     $message .= $message_texte."\n\n";
     //-----------------------------------------------
     //MESSAGE HTML
     //-----------------------------------------------
     $message .= '--'.$frontiere."\n";
     $message .= 'Content-Type: text/html; charset="iso-8859-1"'."\n";
     $message .= 'Content-Transfer-Encoding: 8bit'."\n\n";
     $message .= $message_html."\n\n";
     $message .= '--'.$frontiere."\n";

     //-----------------------------------------------
     //PIECE JOINTE
     //-----------------------------------------------

     $message .= 'Content-Type: application/pdf; name=$name'.'.pdf'."\n";
     $message .= 'Content-Transfer-Encoding: base64'."\n";
     $message .= 'Content-Disposition:attachement; filename='.$name.'.pdf'."\n";

     $message .= chunk_split(base64_encode(file_get_contents($name.'.pdf')))."\n";

     if(mail($email,'Daily Report',$message,$headers))
     {
          echo 'Mail was sent to  '.$email.'<br/>';
     }
     else
     {
          echo 'mail failed...';
     }


//mail($email,"Monthly Report send from my scheduler ahmed for:","ppppp","pppp"); 

//mail($email,"Daily Report for:". $surname,"<html><body>$output</body></html>","MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n"); 



?>

`

OK, there are two things in there I would question. First, like I mentioned before, you may want to include a Content-Length header for attachments, so the clients will know how much data to expect.

Second, why do you chunk_split() the PDF data? Injecting newline characters into the PDF's binary data stream doesn't seem like a great idea. (Although, it's Base64 encoded, so I don't know exactly how that would be handled.)

O, and also, the email meta-data (headers and empty lines) should use Windows style new lines \r\n instead of just \n. Although, this is more a matter of proper style rather than a practical error. Most email clients can deal with Unix style new lines as well.

With all that said, I strongly suggest you adopt a more "robust" email library. The PHP mail() function is fine for simple mails, but if you intend to be sending complex HTML mails and attachemnts, I suggest use either Swift Mailer or PHPMailer. Those already have stable support for these types of mails. No need to reinvent the wheel!

Hi
thank you
really i m new to the php mail system the first time i m using it.
i found mail as example to use than i used it until i found this problem with some mail clients..
what i understood i must change \n to \r\n
also i must include content-length
i will change this and see
for using swiftmailer or phpmailer really i want to know them as i m using database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.