Hi
i have an htm created by ob_start--ob_clean (query from mysql)
i can have more than 1 html each one for a user these htmls are converted to pdf using html2pdf and each file is called by the name of the cleint
ex:if the user name is xxxx===>he will get xxxx.pdf file
my problem how i can send each of these files to a specific user
xxxx.pdf must be attached to xxxx user ..
everything is working perfect only i cannot find a method to send these emails
pls check the last part of the code

----------------html2pdf------------

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($surname.'.pdf','F');

}
    catch(HTML2PDF_exception $e) { 
echo $e; 
}

//-----------------------------------------------
     //DECLARE LES VARIABLES
     //-----------------------------------------------

     $email_expediteur='info@campion.ie';
     $email_reply='email_de_reponse@fai.fr';
     $message_texte='Bonjour,'."\n\n".'Voici un message au format texte';

     $message_html='<html>
     <head>
     <title>Titre</title>
     </head>
     <body>Test de message</body>
     </html>';

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

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

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

     $headers = 'From: "Nom" <'.$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/plain; 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="monthly.pdf"'."\n";
     $message .= 'Content-Transfer-Encoding: base64'."\n";
     $message .= 'Content-Disposition:attachement; filename="monthly.pdf"'."\n\n";

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

     if(mail($email,$sujet,$message,$headers))
     {
          echo 'Le mail a été envoyé';
     }
     else
     {
          echo 'Le mail n\'a pu être envoyé';
     }
Member Avatar for diafol

do you have an smtp server running?

Hi
everything is runing fine..my problem i cannot find a method to:send for each email his attachment
the pdf is created for each user
$html2pdf->Output($surname.'.pdf','F');
if your usename is aaa the pdf will be called aaa.pdf and so and i will have a lot of pdfs in my folder
but when i send emails with attachment i have a problem
i want to send for each user with his attachment
aaa@mail.com must get the aaa.pdf
bbb@use.net must get the bbb.pdf and so..
cheers

See function for attaching file. Also take care to save generated file in folder with 777 permission. then use that file to attach, i set path ../pdf/mail_attach.

<?php

    function attach_file($files,$mime_boundary)
    {


        // preparing attachments
        $message="";
        $filecount= count($files);
        for($x=0;$x<$filecount;$x++)
        {
            $filefullpath="../pdf/mail_attach/".$files[$x]['file_name'];
            $file = fopen($filefullpath,"rb");
            $data = fread($file,filesize($filefullpath));
            fclose($file);
            $data = chunk_split(base64_encode($data));
            $message .= "Content-Type: \"".$files[$x]['file_type']."\";\n" . " name=\"".$files[$x]['file_title']."\"\n" . 
            "Content-Disposition: attachment;\n" . " filename=\"".$files[$x]['file_title']."\"\n" . 
            "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
            if($x<$filecount-1)
                $message .= "--{$mime_boundary}\n";
        }    
        return $message;
    }


    $html2pdf->Output("../pdf/mail_attach/".$surname.'.pdf','F');

    $semi_rand = md5(time());     
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";     


    $files[0]['file_name']="aaa.pdf"; //filename
    $files[0]['file_title']="UserFileAAA"; // file title
    $files[0]['file_type']="application/pdf"; // mime file type

     // Add the headers for a file attachment     
     $headers ="From: {$fromemailid}\n";            

// $headers .="Return-path: {$fromemailid}\n";
$headers .= "MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

    $subject = $db_broad[$bindex]['mail_subject'];

    //$message ="This is a multi-part message in MIME format.\n\n";
    $message ="--{$mime_boundary}\n";
    $message .="Content-type: text/html; charset=iso-8859-1\n";
    $message .="Content-Transfer-Encoding: 7bit\n\n" ;

    $email_text=$message;

    $message .=$email_text."\n\n";


    $attachment=attach_file($files,$mime_boundary);

    if($attachment!="")
        $message .="--{$mime_boundary}\n".$attachment;          


    $sendmail = mail($toemailid ,$subject,$message,$headers,"-f".$fromemailid);

?>

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.