Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将TCPDF与PHP邮件功能结合使用 $to='1!'my@email.ca'; $subject='收据'; $repEmail=rep@sales.ca'; $fileName='receipt.pdf'; $fileatt=$pdf->Output($fileName,'E'); $attachment=chunk\u split($fileatt); $eol=PHP\u eol; $separator=md5(time()); $headers='From:Sender'.$eol; $headers.=“MIME版本:1.0”。$eol; $headers.=“内容类型:多部分/混合;边界=\”.$separator.\”; $message=“--”$separator.$eol; $message.=“内容传输编码:7bit”。$eol.$eol; $message.=“这是一条MIME编码的消息。”。$eol; $message.=“-”$separator.$eol; $message.=“内容类型:text/html;字符集=\“iso-8859-1\”。$eol; $message.=“内容传输编码:8位”。$eol.$eol; $message.=“-”$separator.$eol; $message.=“内容类型:application/pdf;name=\”.$fileName.\”.$eol; $message.=“内容传输编码:base64”。$eol; $message.=“内容处置:附件”。$eol.$eol; $message.=$attachment.$eol; $message.=“--”“分隔符”“--”; if(邮件($to、$subject、$message、$headers)){ $action='action=收据%20Sent'; 标题('Location:../index.php?'。$action); } 否则{ $action='action=Send%20失败'; 标题('Location:../index.php?'。$action); }_Php_Email_Pdf_Phpmailer_Tcpdf - Fatal编程技术网

如何将TCPDF与PHP邮件功能结合使用 $to='1!'my@email.ca'; $subject='收据'; $repEmail=rep@sales.ca'; $fileName='receipt.pdf'; $fileatt=$pdf->Output($fileName,'E'); $attachment=chunk\u split($fileatt); $eol=PHP\u eol; $separator=md5(time()); $headers='From:Sender'.$eol; $headers.=“MIME版本:1.0”。$eol; $headers.=“内容类型:多部分/混合;边界=\”.$separator.\”; $message=“--”$separator.$eol; $message.=“内容传输编码:7bit”。$eol.$eol; $message.=“这是一条MIME编码的消息。”。$eol; $message.=“-”$separator.$eol; $message.=“内容类型:text/html;字符集=\“iso-8859-1\”。$eol; $message.=“内容传输编码:8位”。$eol.$eol; $message.=“-”$separator.$eol; $message.=“内容类型:application/pdf;name=\”.$fileName.\”.$eol; $message.=“内容传输编码:base64”。$eol; $message.=“内容处置:附件”。$eol.$eol; $message.=$attachment.$eol; $message.=“--”“分隔符”“--”; if(邮件($to、$subject、$message、$headers)){ $action='action=收据%20Sent'; 标题('Location:../index.php?'。$action); } 否则{ $action='action=Send%20失败'; 标题('Location:../index.php?'。$action); }

如何将TCPDF与PHP邮件功能结合使用 $to='1!'my@email.ca'; $subject='收据'; $repEmail=rep@sales.ca'; $fileName='receipt.pdf'; $fileatt=$pdf->Output($fileName,'E'); $attachment=chunk\u split($fileatt); $eol=PHP\u eol; $separator=md5(time()); $headers='From:Sender'.$eol; $headers.=“MIME版本:1.0”。$eol; $headers.=“内容类型:多部分/混合;边界=\”.$separator.\”; $message=“--”$separator.$eol; $message.=“内容传输编码:7bit”。$eol.$eol; $message.=“这是一条MIME编码的消息。”。$eol; $message.=“-”$separator.$eol; $message.=“内容类型:text/html;字符集=\“iso-8859-1\”。$eol; $message.=“内容传输编码:8位”。$eol.$eol; $message.=“-”$separator.$eol; $message.=“内容类型:application/pdf;name=\”.$fileName.\”.$eol; $message.=“内容传输编码:base64”。$eol; $message.=“内容处置:附件”。$eol.$eol; $message.=$attachment.$eol; $message.=“--”“分隔符”“--”; if(邮件($to、$subject、$message、$headers)){ $action='action=收据%20Sent'; 标题('Location:../index.php?'。$action); } 否则{ $action='action=Send%20失败'; 标题('Location:../index.php?'。$action); },php,email,pdf,phpmailer,tcpdf,Php,Email,Pdf,Phpmailer,Tcpdf,我已经使用TCPDF很短时间了,现在可以从表单生成PDF文件。它工作得很好,PHP的这一部分并没有改变。现在我想将这些PDF文件发送到我的电子邮件帐户 这封电子邮件实际上是在使用这种编码和附加PDF。问题在于它只是一个大约100字节大小的空白PDF。这当然不是一个有效的PDF,也与表格中的回复无关 我真的不熟悉如何用PHP将文件附加到电子邮件中,如能帮助解决此问题,我将不胜感激 更新 由于似乎有几个人在关注这个问题,我将发布我当前的解决方案。它包括下载PHPMailer,如下所示。我从TCPDF

我已经使用TCPDF很短时间了,现在可以从表单生成PDF文件。它工作得很好,PHP的这一部分并没有改变。现在我想将这些PDF文件发送到我的电子邮件帐户

这封电子邮件实际上是在使用这种编码和附加PDF。问题在于它只是一个大约100字节大小的空白PDF。这当然不是一个有效的PDF,也与表格中的回复无关

我真的不熟悉如何用PHP将文件附加到电子邮件中,如能帮助解决此问题,我将不胜感激

更新

由于似乎有几个人在关注这个问题,我将发布我当前的解决方案。它包括下载PHPMailer,如下所示。我从TCPDF的输出行开始

$to = 'my@email.ca';
$subject = 'Receipt';
$repEmail = 'rep@sales.ca';

$fileName = 'receipt.pdf';
$fileatt = $pdf->Output($fileName, 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());

$headers = 'From: Sender <'.$repEmail.'>'.$eol;
$headers .= 'MIME-Version: 1.0' .$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

$message = "--".$separator.$eol;
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$message .= "This is a MIME encoded message.".$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; 
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--";

if (mail($to, $subject, $message, $headers)){
$action = 'action=Receipt%20Sent';
header('Location: ../index.php?'.$action);
}

else {
$action = 'action=Send%20Failed';
header('Location: ../index.php?'.$action);
}
$attachment=$makepdf->Output('filename.pdf','S');
SENDmail(附件);
函数SENDmail($pdf){
一次需要_('phpmailer/class.phpmailer.php');
$mailer=新的PHPMailer();
$mailer->AddReplyTo('reply@to.ca","答复";;
$mailer->SetFrom($mailer)sent@from.ca“,”发送自“);
$mailer->AddReplyTo('reply@to.ca","答复";;
$mailer->AddAddress('send@to.ca“,”发送到“);
$mailer->Subject='messagewithpdf';
$mailer->AltBody=“要查看邮件,请使用与HTML兼容的电子邮件查看器”;
$mailer->MsgHTML(“消息内容”);
如果($pdf){$mailer->AddStringAttachment($pdf,'filename.pdf');}
$mailer->Send();
}

您有两个选择。您可以将PDF保存到文件并附加该文件,或者将其作为字符串输出。我发现字符串输出更可取:

$attachment = $makepdf->Output('filename.pdf', 'S');
SENDmail($attachment);

function SENDmail($pdf) {
require_once('phpmailer/class.phpmailer.php');
$mailer = new PHPMailer();

$mailer->AddReplyTo('reply@to.ca', 'Reply To');
$mailer->SetFrom('sent@from.ca', 'Sent From');
$mailer->AddReplyTo('reply@to.ca', 'Reply To');
$mailer->AddAddress('send@to.ca', 'Send To');
$mailer->Subject = 'Message with PDF';
$mailer->AltBody = "To view the message, please use an HTML compatible email viewer";
$mailer->MsgHTML('<p>Message contents</p>'));
if ($pdf) {$mailer->AddStringAttachment($pdf, 'filename.pdf');}

$mailer->Send();
}
文件名被忽略,因为它只返回编码字符串。现在,您可以在电子邮件中包含该字符串。我更喜欢在处理这样的附件时使用PHPMailer。使用PHPMailer的AddStringAttachment方法完成以下操作:

$pdfString = $pdf->Output('dummy.pdf', 'S');

我试过几种选择。唯一有效的方法是将PDF保存到一个文件夹,然后通过电子邮件发送

$mailer->AddStringAttachment($pdfString, 'some_filename.pdf');
$pdf->输出(“folder/filename.pdf”、“F”)//将pdf保存到文件夹中
一次需要_('phpmailer/class.phpmailer.php')//phpmailer文件夹所在的位置
$mail=new PHPMailer();
$mail->From=“email.com”;
$mail->FromName=“您的姓名”;
$mail->AddAddress(“email@yahoo.com");
$mail->AddReplyTo(“email@gmail.com“,”您的名字“;
$mail->AddAttachment(“folder/filename.pdf”);//附加保存在文件夹中的pdf
$mail->Subject=“电子邮件主题”;
$mail->Body=“电子邮件正文”;
如果(!$mail->Send())
{
echo“无法发送消息。”;
回显“邮件错误:”.$mail->ErrorInfo;
}
其他的
{
回显“已发送消息”;
} 
回音“发送电子邮件和附件”;

是的,看起来我必须使用外部邮件库。谢谢你的提示。我还想避免使用外部邮件库,但这是一个完美的解决方案。我向你脱帽致敬,大卫。你的服务器是否能够使用
mail()
功能?如果没有,您将无法从
TCPDF
$pdf->Output("folder/filename.pdf", "F"); //save the pdf to a folder
  require_once('phpmailer/class.phpmailer.php'); //where your phpmailer folder is
$mail = new PHPMailer();                    
$mail->From = "email.com";
$mail->FromName = "Your name";
$mail->AddAddress("email@yahoo.com");
$mail->AddReplyTo("email@gmail.com", "Your name");               
$mail->AddAttachment("folder/filename.pdf");      // attach pdf that was saved in a folder
$mail->Subject = "Email Subject";                  
$mail->Body = "Email Body";
if(!$mail->Send())
{
       echo "Message could not be sent. <p>";
       echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
       echo "Message sent";
} 
echo 'sent email and attachment';