我附加了一个pdf文件,但附件没有在邮件中打开。 它在邮件服务器上提供错误
预期:application / pdf(.pdf);发现:application / x-empty
我有以下代码段
<?php
$from='test1@domain.com';
$to = 'test@domain.com';
//define the subject of the email
$subject = 'Test email with attachment';
$message='Startendday reports' ;
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$file = file_get_contents('file.pdf');
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time())); //unique identifier
$file_name='file.pdf';
//standard mail headers
$header = "From: ".$from."\r\n";
$header .= "Reply-To: ".$to. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
//declare multiple kinds of email (plain text + attch)
$header .="Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .="This is a multi-part message in MIME format.\r\n";
//plain txt part
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message. "\r\n\r\n";
//attch part
$header .= "--".$uid."\r\n";
$header .= "Content-Type:application/octet-stream; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content."\r\n\r\n"; //chucked up 64 encoded attch
//sending the mail - message is not here, but in the header in a multi part
if(mail($to, $subject, "", $header)) {
echo "success";
}else {
echo "fail";
}
?>
请帮帮我