如何在Wordpress中将动态生成的文件作为字符串附加到电子邮件
我有一个wordpress网站,通过FPDF生成发票pdf。我想把它附加到电子邮件中,但我不知道如何在Wordpress中实现。生成pdf时,它将作为字符串返回,但无法使用wp_mail函数附加它 这是我当前的代码,它附加了一个noname文件(一个损坏的文件) 可能重复的如何在Wordpress中将动态生成的文件作为字符串附加到电子邮件,wordpress,Wordpress,我有一个wordpress网站,通过FPDF生成发票pdf。我想把它附加到电子邮件中,但我不知道如何在Wordpress中实现。生成pdf时,它将作为字符串返回,但无法使用wp_mail函数附加它 这是我当前的代码,它附加了一个noname文件(一个损坏的文件) 可能重复的 // Generating the invoice PDF on the fly ... $pdf = new PDF(); ... $document = $pdf->Output('', 'S'); // retu
// Generating the invoice PDF on the fly
...
$pdf = new PDF();
...
$document = $pdf->Output('', 'S'); // return the document as a string
// Attaching the PDF to an email
$msg = 'My message';
$semirandom = md5(time());
$header = 'Content-Type: multipart/mixed; boundary=' . $semirandom . '\r\n';
$message = '--'.$semirandom.'\r\n';
$message .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
$message .= "\r\n".$msg."\r\n\r\n";
$message .= "--".$semirandom."\r\n";
$message .= "Content-Type: application/octet-stream; name=\"invoice.pdf\"\r\n";
$message .= "Content-Disposition: attachment; filename=\"invoice.pdf\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n\r\n";
$message .= chunk_split(base64_encode($document));
$message .= "--".$semirandom."--";
@wp_mail($email, 'My subject', $message, $header);