php - Receiving "ATT00001.txt" instead of pdf with the mail function -
i tried send mail attachement mail function, found tutorial jpg , tried modify sending pdf, attachement receive att00001.txt
.
here programm:
<?php // $to = 'mail@test.com'; // subject $subject = 'test pdf'; // random boundary $boundary = md5(uniqid(microtime(), true)); // headers $headers = 'from: test <mail@test.com>'."\r\n"; $headers .= 'mime-version: 1.0'."\r\n"; $headers .= 'content-type: multipart/mixed;boundary='.$boundary."\r\n"; $headers .= "\r\n"; // message $msg = 'this multipart/mixed message.'."\r\n\r\n"; // text $msg .= '--'.$boundary."\r\n"; $msg .= 'content-type:text/plain;charset=utf-8'."\r\n"; $msg .= 'content-transfer-encoding:8bit'."\r\n"; $msg .= 'un message avec une pièce jointe.'."\r\n"; // attachement $file_name = 'test.pdf'; if (file_exists($file_name)) { $file_type = filetype($file_name); $file_size = filesize($file_name); $handle = fopen($file_name, 'r') or die('file '.$file_name.'can t open'); $content = fread($handle, $file_size); $content = chunk_split(base64_encode($content)); $f = fclose($handle); $msg .= '--'.$boundary."\r\n"; $msg .= 'content-type:'.$file_type.';name='.$file_name."\r\n"; $msg .= 'content-transfer-encoding:base64'."\r\n"; $msg .= $content."\r\n"; } // end $msg .= '--'.$boundary."\r\n"; // function mail() mail($to, $subject, $msg, $headers); echo "test pdf"; ?>
i hope me,
best regards ☻♥
Comments
Post a Comment