sendmail - php Why pdf which we send on email not open? -
sendmail - php Why pdf which we send on email not open? -
$namefile = '15_10_2014_.pdf'; $file = './temp/15_10_2014_.pdf'; $to = 'test2@test.com'; $from = "test@test.com"; $eol = "\r\n"; $boundary = "--".md5(uniqid(time())); $message = " <p>text text text</p> "; $subject= '=?utf-8?b?' . base64_encode('Счет на оплату') . '?='; $headers = "mime-version: 1.0;$eol"; $headers .= "content-type: multipart/mixed; boundary=\"$boundary\"$eol"; $headers .= "from: $from\nreply-to: $from\n"; $multipart = "--$boundary$eol"; $multipart .= "content-type: text/html; charset=utf-8$eol"; $multipart .= "content-transfer-encoding: base64$eol"; $multipart .= $eol; $multipart .= chunk_split(base64_encode($message)); $multipart .= "$eol--$boundary$eol"; $multipart .= "content-type: application/octet-stream; name=\"$namefile\"$eol"; $multipart .= "content-transfer-encoding: base64$eol"; $multipart .= "content-disposition: attachment; filename=\"$namefile\"$eol"; $multipart .= $eol; $multipart .= chunk_split(base64_encode($file)); $multipart .= "$eol--$boundary--$eol"; if(!mail($to, $subject, $multipart, $headers)){ $content = $this->return_error_p('mail not send'); } else{ $content = $this->return_true_p('mail send'); }
as result, email pdf attachment, pdf file not open. when open file error: "file format not supported or sent via email , not correctly decoded."
tell me please error?
you need content file:
$openfile = fopen($file, "rb"); $data = fread($openfile, filesize( $filename ) ); fclose($openfile); $file = $data;
enjoy!
php sendmail
Comments
Post a Comment