【发布时间】:2017-06-26 09:19:34
【问题描述】:
我正在尝试在单击超链接时将 fpdf 文件发送到 phpmailer。目前,超链接仅打开 pdf 文件。如何使用 phpmailer 附加它?
打开 PDF 的超链接
<a target="_blank" href="<?php echo SITEURL; ?>/mod/orders/x-SOprint_new.php?id=<?php echo $d['orderID']; ?>"><?php echo $d['orderID']; ?></a>
PHPMAILER 代码
<?php
require 'phpmailer/PHPMailerAutoload.php';
session_start();
$orderID=$_SESSION['orderID'];
$tomailID=$_POST['tmail'];
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "";
$mail->Password = "Password";
$mail->SetFrom("");
$mail->Subject = "mail test for last time";
$mail->Body = "Respected Sir/Madam"
. "Thanks for your Order"
. "The Sales Order Number:"+$orderID+" Date : ,"
. "Sales order Copy Atached in PDF format"
. "\n"
. '\n'
. "\n"
. "This is computer generated Letter , Please do not reply on this Address";
$mail->AddAddress("$tomailID");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent"+$tomailID;
}
?>
FPDF 文件
<?php
$pdf = new FPDF();
global $DB;
$view=$_REQUEST['vbeln'];
require("fpdf/fpdf.php");
$sql = "SELECT * FROM `" . $DB->pre . "party_outstanding_history` WHERE BELNR= '". $view ."'";
$rows = $DB->dbRow($sql);
$custCode= $rows['KUNNR'];
$docDate= $rows['AUGDT'];
$sql1 ="SELECT * FROM `" . $DB->pre . "party_master` WHERE KUNNR = '". $custCode."'";
$rows1 = $DB->dbRow($sql1);
$partyname = $rows1['NAME1'];
$pdf->AddPage();
$pdf->Rect(5, 5, 200, 287);
$pdf->SetFont('helvetica','B',12);
$pdf->Text(90,15,'JHAMPSTEAD DIVISION',1,2,'C');
$pdf->Text(70,20,'DEBIT/CREDIT NOTE',1,2,'C');
$pdf->SetFont('helvetica','',10);
$pdf->Text(10,35,'Doc No :',1,2,'C');
$pdf->Text(120,35,'Doc Date :',1,2,'C');
$pdf->Text(10,40,'Customer :',1,2,'C');
$pdf->Text(10,45,'Customer Name :',1,2,'C');
$pdf-> Ln();
$pdf->Text(10,60,'Agent :',1,2,'C');
$pdf->Text(10,65,'Reference :',1,2,'C');
$pdf->Text(10,70,'Text :',1,2,'C');
$pdf-> Ln();
$pdf->SetFont('Arial','B',9);
$pdf->SetXY(11,103);
$pdf->Cell(25,7,'BILL NO.',1,0,'L',0);
$pdf->Cell(22,7,'DATE',1,0,'L',0);
$pdf->Cell(22,7,'AMOUNT',1,0,'L',0);
$pdf->Cell(18,7,'LDAYS',1,0,'L',0);
$pdf->Cell(18,7,'EP1',1,0,'L',0);
$pdf->Cell(18,7,'EP2',1,0,'L',0);
$pdf->Cell(22,7,'INTDR1',1,0,'L',0);
$pdf->Cell(22,7,'INTAMT',1,0,'L',0);
$pdf->Cell(18,7,'NET',1,0,'L',0);
$pdf-> Ln();
$pdf-> Ln();
$pdf->SetX(11);
$pdf->Cell(47,7,'TOTAL',1,0,'L',0);
$pdf->Cell(22,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Cell(22,7,'',1,0,'L',0);
$pdf->Cell(22,7,'',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->Ln();
$pdf->SetX(156);
$pdf->Cell(22,7,'Net Amt.',1,0,'L',0);
$pdf->Cell(18,7,'',1,0,'L',0);
$pdf->SetFont("Arial","B","8");
$pdf->SetXY (5,271);
$pdf->Output();
?>
【问题讨论】:
-
也就是说你想通过电子邮件发送PDF文件对吧?
-
是的,没错
-
我链接到的重复问题显示了如何将 fpdf 生成与通过 PHPMailer 发送集成,它不需要使用外部文件或辅助 HTTP 请求。