Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 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 Reply

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);
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...