$envelope["from"]= "xxx@xxx.info"; $envelope["to"] = "xxx@gmail.com"; //$envelope["cc"] = "bar@example.com"; $part1["type"] = TYPEMULTIPART; $part1["subtype"] = "mixed"; $filename = "attachment/test.txt"; $fp = fopen($filename, "r"); $contents = fread($fp, filesize($filename)); fclose($fp); $part2["type"] = TYPEAPPLICATION; $part2["encoding"] = ENCBINARY; $part2["subtype"] = "octet-stream"; $part2["description"] = basename($filename); $part2["contents.data"] = $contents; $part2["type"] = TYPEAPPLICATION; $part2["encoding"] = ENCBASE64; $part2["subtype"] = "octet-stream"; $part2["description"] = $filename; $part2['disposition.type'] = 'attachment'; $part2['disposition'] = array ('filename' => $filename); $part2['type.parameters'] = array('name' => $filename); $part2["contents.data"] = base64_encode($contents); $part3["type"] = TYPETEXT; $part3["subtype"] = "plain"; $part3["description"] = "description3"; $part3["contents.data"] = "contents.data3\n\n\n\t"; $body[1] = $part1; $body[2] = $part2; $body[3] = $part3; $mail=imap_mail_compose($envelope,$body); list($t_header,$t_body)=split("\r\n\r\n",$mail,2); $t_header=str_replace("\r",'',$t_header); $result=imap_mail("danielss89@gmail.com","wallah",$t_body,$t_header);