Php sends an email with a pdf attachment with a long string. how can I solve the RT problem? the e-mail attachment sent is not a pdf file, but a long string. the code for sending an email is as follows: function & nbsp; mail ($ mailto, & nbsp; $ userid, & nbsp; $ data) {& php sends a long string of emails with pdf attachments. how can I solve this problem?
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;
} Php email pdf shared:
------ Solution --------------------
You use phpmailer
------ Solution --------------------
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();
------ Solution --------------------
It may be because the boundary settings are incorrect, resulting in a parsing error.