Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

php send email with attachment

How to send the email with resume attachment ,

i take snippet from this place Click here

In this site, snippet works fine,

Even i got the mail, but attachment is not working, am getting attment as noname with 0kb

size file, What is Issue in that snippet ,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
 function mail_attachment($to, $subject, $message, $from, $file) {
  // $file should include path and filename
  $filename = basename($file);
  $file_size = filesize($file);
  $content = chunk_split(base64_encode(file_get_contents($file))); 
  $uid = md5(uniqid(time()));
  $from = str_replace(array("
", "
"), '', $from); // to prevent email injection
  $header = "From: ".$from."
"
      ."MIME-Version: 1.0
"
      ."Content-Type: multipart/mixed; boundary="".$uid.""

"
      ."This is a multi-part message in MIME format.
" 
      ."--".$uid."
"
      ."Content-type:text/plain; charset=iso-8859-1
"
      ."Content-Transfer-Encoding: 7bit

"
      .$message."

"
      ."--".$uid."
"
      ."Content-Type: application/octet-stream; name="".$filename.""
"
      ."Content-Transfer-Encoding: base64
"
      ."Content-Disposition: attachment; filename="".$filename.""

"
      .$content."

"
      ."--".$uid."--"; 
  return mail($to, $subject, "", $header);
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...