Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------------------------FPDF CREAZIONE E INVIO ALLEGATO EMAIL CON CANCELLAZIONE
- FPDF code:
- require_once('fpdf/fpdf.php');
- $fpdf = new FPDF();
- $text="test";
- $fpdf->SetMargins(0, 0, 0);
- $fpdf->SetAutoPageBreak(true, 0);
- define('FPDF_FONTPATH', 'font/');
- $fpdf->AddFont('Verdana', '','verdana.php'); // Standard Arial
- $fpdf->addPage('L');
- $fpdf->Image('images/certificate.jpg', 0, 0, 297, 210);
- $fpdf->SetFont('Verdana', '');
- $fpdf->SetFontSize(28);
- $fpdf->SetTextColor(32, 56, 100);
- $fpdf->SetXY(108, 52); //
- $fpdf->Cell(80, 6, $text, 0,0, 'C');
- $fpdf->Output('Filename.pdf', 'i');
- PHPMailer code:
- require 'phpmailer/PHPMailerAutoload.php';
- $mail = new PHPMailer;
- $mail->IsSMTP(); // Set mailer to use SMTP
- $mail->Host = 'gator3095'; // Specify main and backup server
- $mail->Port = 587; // Set the SMTP port
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'username'; // SMTP username
- $mail->Password = 'password'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
- $mail->From = 'test@hotmail.com.com';
- $mail->FromName = 'John Doe';
- $mail->AddAddress('recipient@hotmail.com', ''); // Add a recipient
- $mail->IsHTML(true); // Set email format to HTML
- $mail->Subject = 'subject';
- $mail->Body = 'message body';
- $mail->AltBody = 'messge body';
- $mail->AddAttachment("c:/temp/test.php", "test.php");
- if(!$mail->Send()) {
- echo 'Message could not be sent.';
- echo 'Mailer Error: ' . $mail->ErrorInfo;
- exit;
- }
- echo 'Message has been sent';
- 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).
- 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");
- And finally, before your last echo, add unlink('Filename.pdf'); to delete the temporary PDF file you've just sended.
- ------------------------altra versione-----
- require('lib/FPDF/fpdf.php');
- require 'lib/PHPMailer/PHPMailerAutoload.php';
- $pdf = new FPDF();
- $pdf->AddPage();
- $pdf->SetFont('Arial','B',16);
- $pdf->Write(5,'Hello India');
- $mail = new PHPMailer;
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = SmtpServer; // SMTP server
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = SmtpUsername; // SMTP username
- $mail->Password = SmtpPassword; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->From = FromEmail;
- $mail->Port = 587; // SMTP Port
- $mail->FromName = 'testing';
- $mail->Subject = $subject;
- $mail->Body = $body;
- $mail->AddAddress($emails);
- $mail->addStringAttachment($pdf->Output("S",'OrderDetails.pdf'), 'OrderDetails.pdf', $encoding = 'base64', $type = 'application/pdf');
- return $mail->Send();
Add Comment
Please, Sign In to add comment