Guest User

Untitled

a guest
Aug 8th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. ---------------------------------------------------------------------------------FPDF CREAZIONE E INVIO ALLEGATO EMAIL CON CANCELLAZIONE
  2.  
  3. FPDF code:
  4.  
  5. require_once('fpdf/fpdf.php');
  6. $fpdf = new FPDF();
  7. $text="test";
  8.  
  9. $fpdf->SetMargins(0, 0, 0);
  10. $fpdf->SetAutoPageBreak(true, 0);
  11.  
  12. define('FPDF_FONTPATH', 'font/');
  13.  
  14. $fpdf->AddFont('Verdana', '','verdana.php'); // Standard Arial
  15.  
  16. $fpdf->addPage('L');
  17.  
  18. $fpdf->Image('images/certificate.jpg', 0, 0, 297, 210);
  19.  
  20. $fpdf->SetFont('Verdana', '');
  21. $fpdf->SetFontSize(28);
  22. $fpdf->SetTextColor(32, 56, 100);
  23. $fpdf->SetXY(108, 52); //
  24. $fpdf->Cell(80, 6, $text, 0,0, 'C');
  25.  
  26. $fpdf->Output('Filename.pdf', 'i');
  27.  
  28. PHPMailer code:
  29.  
  30. require 'phpmailer/PHPMailerAutoload.php';
  31. $mail = new PHPMailer;
  32. $mail->IsSMTP(); // Set mailer to use SMTP
  33. $mail->Host = 'gator3095'; // Specify main and backup server
  34. $mail->Port = 587; // Set the SMTP port
  35. $mail->SMTPAuth = true; // Enable SMTP authentication
  36. $mail->Username = 'username'; // SMTP username
  37. $mail->Password = 'password'; // SMTP password
  38. $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  39. $mail->From = 'test@hotmail.com.com';
  40. $mail->FromName = 'John Doe';
  41. $mail->AddAddress('recipient@hotmail.com', ''); // Add a recipient
  42. $mail->IsHTML(true); // Set email format to HTML
  43.  
  44. $mail->Subject = 'subject';
  45. $mail->Body = 'message body';
  46. $mail->AltBody = 'messge body';
  47. $mail->AddAttachment("c:/temp/test.php", "test.php");
  48.  
  49. if(!$mail->Send()) {
  50. echo 'Message could not be sent.';
  51. echo 'Mailer Error: ' . $mail->ErrorInfo;
  52. exit;
  53. }
  54. echo 'Message has been sent';
  55.  
  56. REeplace $fpdf->Output('Filename.pdf', 'i'); by $fpdf->Output('Filename.pdf', 'S'); to save your PDF on the harddrive instead of sending it directly to the browser (as explained in the doc).
  57.  
  58. Then call your FPDF code to generate the PDF file in the begining or before your PHPmailer.php code, replace $mail->AddAttachment("c:/temp/test.php", "test.php"); by $mail->AddAttachment("[...the exact place where your file is..]/Filename.pdf", "Filename.pdf");
  59.  
  60. And finally, before your last echo, add unlink('Filename.pdf'); to delete the temporary PDF file you've just sended.
  61.  
  62. ------------------------altra versione-----
  63.  
  64. require('lib/FPDF/fpdf.php');
  65. require 'lib/PHPMailer/PHPMailerAutoload.php';
  66. $pdf = new FPDF();
  67. $pdf->AddPage();
  68. $pdf->SetFont('Arial','B',16);
  69. $pdf->Write(5,'Hello India');
  70.  
  71. $mail = new PHPMailer;
  72. $mail->isSMTP(); // Set mailer to use SMTP
  73. $mail->Host = SmtpServer; // SMTP server
  74. $mail->SMTPAuth = true; // Enable SMTP authentication
  75. $mail->Username = SmtpUsername; // SMTP username
  76. $mail->Password = SmtpPassword; // SMTP password
  77. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  78. $mail->From = FromEmail;
  79. $mail->Port = 587; // SMTP Port
  80. $mail->FromName = 'testing';
  81.  
  82. $mail->Subject = $subject;
  83. $mail->Body = $body;
  84. $mail->AddAddress($emails);
  85. $mail->addStringAttachment($pdf->Output("S",'OrderDetails.pdf'), 'OrderDetails.pdf', $encoding = 'base64', $type = 'application/pdf');
  86. return $mail->Send();
Add Comment
Please, Sign In to add comment