Ok, it's the end of the day, and I'm tired of reading other posts and getting confused.
I am trying to use the suggestion on php.net for mailing out attachments using the mail() function. I am trying to send a .csv file. Here is my code :
$subject="";
$body="";
$email_to="xxx@xxx.com";
$reply_to="xxx@xxx.com";
$email_cc="xxx@xxx.com";
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="\r";
} else {
$eol="\n";
}
$f_name='files/names_'.$filedate.'.csv'; // this is my filepath
$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents));
$f_type=filetype($f_name);
fclose($handle);
$headers = 'From: '.$reply_to.' <>'.$eol;
$headers .= 'Reply-To: '.$reply_to.''.$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$body.= "Content-Type: application/octet-stream; name=\"".$file_to_create."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment; filename=\"".$file_to_create."\"".$eol.$eol;
$body .= $f_contents.$eol.$eol;
$body .= "Content-Type: multipart/alternative".$eol;
$body .= "--".$mime_boundary."--".$eol.$eol;
mail($email_to, $subject, $body, $headers);
Thanks.