Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
如何在Wordpress中将动态生成的文件作为字符串附加到电子邮件_Wordpress - Fatal编程技术网

如何在Wordpress中将动态生成的文件作为字符串附加到电子邮件

如何在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

我有一个wordpress网站,通过FPDF生成发票pdf。我想把它附加到电子邮件中,但我不知道如何在Wordpress中实现。生成pdf时,它将作为字符串返回,但无法使用wp_mail函数附加它

这是我当前的代码,它附加了一个noname文件(一个损坏的文件)

可能重复的
// 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);