php 发邮件附件pdf,使用PHP发送带有PDF文件附件的电子邮件

好的,这是我的第一个帖子,我在线搜索但没有运气.

我正在做实习,我正在开展一个项目,要求我创建一个网页,当用户提交他/她的信息时生成一个pdf文件.一旦客户点击提交按钮,就需要做三件事:

>将信息存储到数据库(完成),

>向员工发送包含新客户信息(已完成)的电子邮件,以及

>向客户发送带有pdf文件附件(不工作)的“谢谢消息”电子邮件.

我的意思是,客户确实收到了一封电子邮件,但是当他/她打开pdf文件时,我收到以下错误消息:

“Acrobat could not oen ‘file_name’ because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment and wasn’t correctly decoded)…”

请记住,这是我创建pdf文件附件项目的时间.如果有人可以帮我解决这个问题,那就太好了.谢谢!

这是我的代码:

// once there are no errors, as soon as the customer hits the submit button, it needs to send an email to the staff with the customer information

$msg = "Name: " .$_POST['name'] . "\n"

."Email: " .$_POST['email'] . "\n"

."Phone: " .$_POST['telephone'] . "\n"

."Number Of Guests: " .$_POST['numberOfGuests'] . "\n"

."Date Of Reunion: " .$_POST['date'];

$staffEmail = "staffinfo";

mail($staffEmail, "You have a new customer", $msg); // using the mail php function to send the email. mail(to, subject line, message)

//once the customer submits his/her information, he/she will receive a thank you message attach with a pdf file.

$pdf=new FPDF();

$pdf->AddPage();

$pdf->SetFont("Arial", "B", 16);

$pdf->Cell(40, 10, "Hello World!");

// email information

$to = $_POST['email'];

$from = $staffEmail;

$subject = "Thank you for your business";

$message = "Thank you for submitting your information!";

// a random hash will be necessary to send mixed content

$separator = md5(time());

// carriage return type (we use a PHP end of line constant)

$eol = PHP_EOL;

// attachment name

$filename = "yourinformation.pdf";

// encode data (puts attachment in proper format)

$pdfdoc = $pdf->Output("", "S");

$attachment = chunk_split(base64_encode($pdfdoc));

// encode data (multipart mandatory)

$headers = "From: ".$from.$eol;

$headers .= "MIME-Version: 1.0".$eol;

$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;

$headers .= "Content-Transfer-Enconding: 7bit".$eol;

$headers .= "This is a MIME encoded message.".$eol.$eol;

// message

$headers .= "--".$separator.$eol;

$headers .= "Content-Type: text/html; charsrt=\"iso-8859-1\"".$eol;

$headers .= $message.$eol.$eol;

// attachment

$headers .= "--".$separator.$eol;

//$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;

$headers .= "Content-Type: application/zip; name=\"".$filename."\"".$eol;

$headers .= "Content-Transfer-Encoding: base64".$eol;

$headers .= "Content-Disposition: attachment".$eol.$eol;

$headers .= $attachment.$eol.$eol;

$headers .= "--".$separator."--";

// send message

mail($to, $subject, $message, $headers);

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值