PHP Email PDF
RT, the email attachment is not a PDF file, it becomes a long string of strings,
The code for my email is as follows:
function mail ($mailto, $userid, $data) {
Global $dsql, $cfg _adminemail, $cfg _webname, $cfg _basehost, $cfg _memberurl;
$mailtitle = $cfg _webname. ": Notice";
$file =fopen ("D:/xampp/htdocs/pdftemp/dsfasdf.pdf", "R");
$fileName = $data [' oid ']. PDF ';
$mimeType = "Application/pdf";
$boundary = "Nextpart_". Uniqid (""); Delimiter 1
$boundary 2 = "nextpart2_". Uniqid (""); Delimiter 2
Email header
$headers = "From:". $cfg _adminemail. " \r\nreply-to: $cfg _adminemail ";
$headers. = "content-type:multipart/mixed; Boundary=\ "$boundary 1\" \ r \ n ";
Read file
$read = Fread ($file, FileSize ("d:/xampp/htdocs/pdftemp/dsfasdf.pdf"));
We use the Base64 method to encode it.
$read = Base64_encode ($read);
Cut this long string into small chunks of 76 characters per line
$read = Chunk_split ($read);
The following is the Mailbody body
$mailbody = "--$boundary 1----$boundary 2
content-type:text/plain;charset=iso-8859-1;
Content-transfer-encoding:8bit ";
$mailbody. = ' to: '. $userid. ',
This is mailbody--$boundary 2--';
Here is the attachment section
$mailbody. = "--$boundary 1
content-type:text/html; Name= $fileName
Content-disposition:inline; Filename= $fileName
Content-transfer-encoding:8bit
$read
-$boundary ";
$status = Smail ($mailto, $mailtitle, $mailbody, $headers);
Setmail ($mailto, $mailtitle, $mailbody, $headers, $status);
return $status;
}
Reply to discussion (solution)
You use Phpmailer to
Is this probably not the type of attachment you are specifying?
Attachment$body. = "--". $separator. $eol; $body. = "Content-type:application/octet-stream; Name=\ "". $filename. " \ "". $eol; $body. = "Content-transfer-encoding:base64". $eol; $body. = "Content-disposition:attachment". $eol. $eol; $body. = $ Attachment. $eol; $body. = "--". $separator. " --";
Recommend the upstairs
$email = new Phpmailer (); $email->from = ' you@example.com '; $email->fromname = ' Your Name '; $email Subject = ' Message Subject '; $email->body = $bodytext; $email->addaddress (' Destinationaddress@example.com '); $file _to_attach = ' path_of_your_file_here '; $email->addattachment ($file _to_ Attach, ' nameoffile.pdf '); return $email->send ();
It is possible that the boundary settings are incorrect, resulting in parsing errors.