A few years ago I wrote a class for sending emails with attachments - it took a while to get it to work so the following may or may not work initially though the functions are derived from that original class. I cannot test this currently but hope it will be of use in solving your issue.
/* utility functions ripped from the class */
function getmimetype( $filepath ){
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mimetype = finfo_file( $finfo, $filepath );
finfo_close( $finfo );
return $mimetype;
}
function multipartBoundary() { return "==Multipart_Boundary_x".md5( microtime() )."x"; }
function htmlmessage( $message, $title ){
$stream=array();
$stream[]="\r\n";
$stream[]="<html>\r\n";
$stream[]="<head>\r\n";
$stream[]="<title>$title</title>\r\n";
$stream[]="</head>\r\n";
$stream[]="<body>\r\n";
$stream[]="$message\r\n";
$stream[]="</body>\r\n";
$stream[]="</html>\r\n\r\n";
return implode( '', $stream );
}
function addattachment( $file=false, $i=1 ){
try{
if( $file && file_exists( realpath( $file ) ) ){
$filename = pathinfo( realpath( $file ),PATHINFO_BASENAME );
$data = file_get_contents( realpath( $file ) );
$chunkeddata = chunk_split( base64_encode( $data ) );
$filesize=filesize( realpath( $file ) );
$filelastmod=date( "Y-m-d G:i:s", filemtime( realpath( $file ) ) );
$contenttype=getmimetype( realpath( $file ) );
$contentmd5=md5( $file );
$contentid="part{$i}.".substr( md5( $file ),0,8 ).".".substr( sha1( $file ),0,8 ).".".substr( sha1( $filesize ), 1,8 ).".".crc32( $file );
$stream=array();
$stream[]="Content-Type: \"{$contenttype}\"; name=\"{$filename}\"\n";
$stream[]="Content-Description: \"{$filename}\"\n";
$stream[]="Content-ID: <{$contentid}>\n";
$stream[]="Content-MD5: \"{$contentmd5}\"\n";
$stream[]="Content-features: \"{$contenttype}, {$filename}\"\n";
$stream[]="Content-Disposition: attachment; filename=\"{$filename}\"; size={$filesize};\n modification-date=\"{$filelastmod}\";\n";
$stream[]="Content-Transfer-Encoding: base64\n\n";
$stream[]="{$chunkeddata}\n\n";
clearstatcache();
return implode( '', $stream );
} else {
throw new Exception('does the file exist?');
}
return 'error';
}catch( Exception $e ){
exit( $e->getMessage() );
}
}
$file = $apply_data['doc'];
$job_email = $mail['email'];
$email = $apply_data['email'];
$to = "help@jnvhelp.com,".$job_email.",".$email."";
$url = "kamla.nigam@outlook.com";
$time = date("Y/m/d");
$message = "JNV JOB REQUEST";
$attachment = $View_Path . $file;
$charset = 'iso-8859-1';
$boundary = multipartBoundary();
$header = "From: JNV HELP\r\n";
$header .= "Cc: $url\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header.="Content-Type: multipart/mixed; boundary=\"".$boundary."\";\r\n\r\n";
$header.="This is a multi-part message in MIME format.\r\n";
$header.="--".$boundary."\r\n";
$header.="Content-Type: text/html; charset=\"".$charset."\"\r\n";
$header.="Content-Transfer-Encoding: 7bit\r\n\r\n";
$header.= htmlmessage( $message, 'HELP' ) . "\r\n\r\n";
$header.="--".$boundary."\r\n";
$header.="Content-type: text/plain; charset=\"".$charset."\"\r\n\r\n";
$header.=strip_tags( $message )."\r\n\r\n";
$header.="--".$boundary."\r\n";
/* try to add the attachment */
$header.=addattachment( $attachment, 1 )."\r\n\r\n";
$header.="--".$boundary."--";
/* try to send email */
$retval = @mail( $to, $subject, $message, $header );
/* further processing if $retval is true */
You could easily use this to send multiple attachments by using an array, like this
/* assumed that $files is a populated array of filepaths */
foreach( $files as $index => $file ){
$header.=addattachment( $file, ( $index + 1 ) )."\r\n\r\n";
$header.="--".$boundary."\r\n";
}
Good luck..