Monday 1 August 2011

How to send pdf or File as Attachment with mail in PHP

To send any type of file or pdf as attachment through any server from PHP. always use php mailer class function

<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsMail();

$mail->AddAddress("email@example.com");
$mail->Subject = "Test 1";
$mail->Body = "Test 1 of PHPMailer.";
$mail->AddAttachment('file/sample1.pdf');
$mail->AddAttachment('file/image1.jpg');

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
   echo "Letter sent";
}
?>



below is the link for download of php mailer class files and examples
http://www.keepandshare.com/doc/3025720/phpmailer-5-2-0-zip-august-1-2011-6-19-pm-63k

2 comments:

  1. Sir as per my requirement I have a final page. As per client requirement he want that this final step need to send as a mail to client and it should be in pdf and printable format.

    Kindly help me for this issue.

    Thanks & Regards,

    Vinod Verma

    ReplyDelete
  2. PDFs file is itself an printable. to send a pdf file, first it should be create by php create pdf component then would be saved in project root folder , from there you can send it as attachment by using above code

    ReplyDelete