Steps to attach pdf file in php mail:
1. Today one of the most popular libray for the mails in the php is Php mailer. So download the php mailer from https://github.com/PHPMailer/PHPMailer
2. Copy the only single file that is required from your downloaded 'class.phpmailer.php' paste the file in the folder wherever you want in your server and include it like
require_once('class.phpmailer.php');
3. Now here is the complete code to know how to attach the pdf in the mail (in case for the pdf creation please follow this tutorial "http://www.onenightstudy.com/2016/02/simplest-way-to-create-pdf-file-in-php.html")
require_once('fpdflib/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$email = "test@onenightstudy.com";
$mail->AddAddress($email, "");
$mail->Subject = "Test mail with pdf attachment";
$mail->MsgHTML("This is the boy of the mail");
$path = "../pdf_files/test.pdf"; //path of the pdf file
$mail->AddAttachment($path, '', $encoding = 'base64', $type = 'application/pdf');
$mail->Send();
4. So by this way you can attach pdf to your mail in case of any example of using the php mailer go to the examples the library you downloaded. Also can contact me if need further help.
Comments
Post a Comment