通过php邮件中的电子邮件从数据库发送pdf

时间:2017-01-07 05:23:45

标签: php mysql email pdf

我正在尝试通过php Mailer从数据库发送pdf文件。当我从数据库中获取文件并将其保存在$ document中并回显它。它正确回声。但是当我在addAttachment函数中放入相同的$ document时,电子邮件会发送但没有附件。这是我的代码

 require("PHPMailer-master/class.phpmailer.php");
 $link = mysql_connect("server", "username", "password") or die(mysql_error());
 mysql_select_db("database") or die(mysql_error());


 $email = new PHPMailer();

$email->From      = 'info@email.com';

$email->FromName  = 'xxxxxxxx';

$email->Subject   = 'xxxxxxxxxxxxxxxxx';

$email->Body      = 'xxxxxxxxxxxxxxxxxxx';

$email->AddAddress( 'saad@gmail.com' );

 $result = mysql_query("SELECT file FROM pdf WHERE cnic = 1610209991607", $link) or die("There is an error in the connection");

$document1=mysql_result($result, 0, 'file'); 

header('Content-type: application/pdf');

//echo $document1;//it works correctly

  //$file_to_attach = '$document1';

  //$email->AddAttachment($doucment1, 'PayRoll.pdf');//it send the attachment when I attach the file from a folder like AddAttachment(my.pdf);

    return $email->Send();`

0 个答案:

没有答案