Php sends a long string of emails with pdf attachments. how can I solve this problem? php email pdf
RT: The email attachment is not a pdf file, but a long string,
The code for sending an email is as follows:
Function mail ($ mailto, $ userid, $ data ){
Global $ dsql, $ pai_adminemail, $ pai_webname, $ pai_basehost, $ pai_memberurl;
$ Mailtitle = $ pai_webname. ": Notification ";
$ File = fopen ("D:/xampp/htdocs/empty temp/dsfasdf.pdf", "r ");
Invalid filename=$data='oid ';
$ MimeType = "application/pdf ";
$ Boundary = "nextpart _". uniqid (""); // delimiter 1
$ Boundary2 = "nextpart2 _". uniqid (""); // delimiter 2
// Email header
$ Headers = "From:". $ pai_adminemail. "\ r \ nReply-To: $ pai_adminemail ";
$ Headers. = "Content-type: multipart/mixed; boundary = \" $ boundary1 \ "\ r \ n ";
// Read the file
$ Read = fread ($ file, filesize ("D:/xampp/htdocs/sharetemp/dsfasdf.pdf "));
// We use base64 to encode it.
$ Read = base64_encode ($ read );
// Cut the long string into small pieces consisting of 76 characters in each line
$ Read = chunk_split ($ read );
// The following is the mailbody body.
$ Mailbody = "-- $ boundary1 ---- $ boundary2
Content-type: text/plain; charsets = ISO-8859-1;
Content-transfer-encoding: 8bit ";
$ Mailbody. = 'to:'. $ userid .',
This is mailbody -- $ boundary2 --';
// The Attachment section is as follows:
$ Mailbody. = "-- $ boundary1
Content-type: text/html; name = $ fileName
Content-disposition: inline; filename = $ fileName
Content-transfer-encoding: 8bit
$ Read
-- $ Boundary1 --";
$ Status = smail ($ mailto, $ mailtitle, $ mailbody, $ headers );
SetMail ($ mailto, $ mailtitle, $ mailbody, $ headers, $ status );
Return $ status;
}
Reply to discussion (solution)
You use phpmailer
Maybe you have not specified the attachment type?
// 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."--";
Recommended 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 may be because the boundary settings are incorrect, resulting in a parsing error.