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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
Php 添加附件文件时出现电子邮件问题_Php_Email - Fatal编程技术网

Php 添加附件文件时出现电子邮件问题

Php 添加附件文件时出现电子邮件问题,php,email,Php,Email,当我试图发送带有附件文件的电子邮件时,我遇到了问题,我只收到了带有空白附件的邮件,我如何修复它。这是我的密码: $html2pdf = new HTML2PDF("P","A4", "fr"); $html2pdf->writeHTML($content, isset($_GET['vuehtml'])); $to = "example@yahoo.com"; $subject = "Voucher Mediskon"; $random_hash = md5(date("r", time

当我试图发送带有附件文件的电子邮件时,我遇到了问题,我只收到了带有空白附件的邮件,我如何修复它。这是我的密码:

$html2pdf = new HTML2PDF("P","A4", "fr");
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$to = "example@yahoo.com"; 
$subject = "Voucher Mediskon";
$random_hash = md5(date("r", time()));
$headers = "From: Admin Mediskon<admin@" . $domain . ">\r\nReply-To: admin@" . $domain;
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode( $html2pdf->Output("", "S") ));
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Terimakasih telah membeli voucher kami. Mediskon</h2>
<p>Silakan <b>unduh ( download )</b> voucher pada <b>attachment</b> yang kami kirim.</p>
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: application/pdf; name="voucher.pdf" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php 
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
$html2pdf=新的html2pdf(“P”、“A4”、“fr”);
$html2pdf->writeHTML($content,isset($\u GET['vuehtml']);
$to=”example@yahoo.com"; 
$subject=“凭证Mediskon”;
$random_hash=md5(日期(“r”,time());
$headers=“From:Admin Mediskon\r\n请提交至:Admin@”$领域;
$headers.=“\r\n内容类型:多部分/混合;边界=\”PHP混合-“$random\u散列。”\”;
$attachment=chunk\u split(base64\u编码($html2pdf->Output(“,“S”));
ob_start();
?>
--PHP混合-
内容类型:多部分/备选;boundary=“PHP alt-”
--PHP alt-
内容类型:文本/纯文本;charset=“iso-8859-1”
内容传输编码:7bit
--PHP alt-
内容类型:text/html;charset=“iso-8859-1”
内容传输编码:7bit
Terimakasih telah membeli-kami。麦迪斯科
Silakan unduh(下载)凭证pada附件yang kami kirim

--PHP alt--- --PHP混合- 内容类型:application/pdf ;;name=“凭证.pdf” 内容传输编码:base64 内容配置:附件 --PHP混合---
不要直接使用PHP的邮件函数。它缺乏安全感,缺乏灵活性。另外,你正在重新发明轮子。以下是两个支持HTML和文件附件的优秀电子邮件库:

我刚收到一封带有空白附件的邮件

因此,问题不在于电子邮件,也不在于将文件附加到电子邮件的过程

您是否查看了消息中的原始数据以查看附件的长度是否为空


你有没有试过把生成的PDF写进一个文件来检查它的内容?

也许会清理一下你的帖子,很难读AS-IS.如果这不是为了学习MIME邮件的工作原理,考虑使用一个库。我不同意,它非常灵活,因此允许人们用它编写不安全的代码。当然,如果你不知道自己在做什么,这些包装可以让生活变得不那么危险。我所说的“不灵活”是指API不足以添加附件等。是的,您可以将任何您喜欢的内容导入
mail()
,但它很容易被绊倒。也许我会使用邮件功能发送简单的电子邮件,了解它很好。我用SwiftMailer尝试你的建议,它很好,看起来我会使用它很长时间。是的,我会这样做,但有时我根本没有附件。。。所以我得出结论,我的代码中有错误。。。你能修好它吗,或者我的代码是对的,或者我的代码没有错。。。