Add pdf app to mime smtp

I am using mime smtp yo send mail. my problem is mail goes without attachment. I want to send a PDF email with an attachment. my code looks like this

$a = $fpdf->writeHTML($fpdf, true, false, true, false, '')  ;
    //$a = $fpdf->Output()  ;


    $host     = 'smtp.ample.co.in';
$username = 'nasadnivas@aadsmple.co.in';
$password = 'asa3';

$to = "namadsivas@ampxle.co.in";
$from = "nadnivas@amsple.co.in";
$subject = "Attachments Test";
$filename = "test";

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

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

$text = "Plain Text Email Content";
$html = "HTML Email Content\n";
//$attachment = "mail_serinv.php?tchyear=2014&tchfyear=14&tchcid=001&tninvid=105466&tcpflag=I&tcnflag=L";

$mime = new Mail_mime();
$mime -> setTXTBody($text);
$mime -> setHTMLBody($html);
$mime -> addAttachment($a, 'text/plain',$filename,false);

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

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

if(PEAR::isError($mail)) {
  echo $mail->getMessage();
} else {
  echo 'Message sent';
}

      

I am looking for many links and found it unhelpful. help me find a solution

+3


source to share


1 answer


Try the following:

Saving the PDF file on the server (make sure you have 777 write permissions for this folder!): - See more: http://blog.startq.com/2011/10/25/fpdf-output-methods-for -pdf-files-in-php / # sthash.J5K9EQ4h.dpuf



$a = $fpdf->Output('directory/yourfilename.pdf','F');
...

$mime -> addAttachment($a, 'application/pdf',$filename,true);

      

0


source







All Articles