Hi guys,
I've been having a bit of an issue with php today and it has me totally stumped.
Hopefully someone on here can point out my mistake.
I have a function for sending an email with attachments. This works bar one small issue.
! is appearing in the email body and is screwing up part of the formatting
Below is the code:
function xmail($to, $subject, $text, $ref) {
/* */
$filepath = "../../images/uploads/".$ref."/";
$vmLink ="";
$vwLink ="";
if ($handle = opendir($filepath)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$extArr = explode(".", $file);
$extStr = $extArr[1];
if($extStr !="mov" && $extStr !="wmv"){
$files[] = $filepath.$file;
}else{
$fileType = substr($file,15,4);
if($fileType == "_vm_"){
$link1 = "http://www.domain.com/images/uploads/".$ref."/".$file;
$vmLink = "Movie link download: <a href='$link1'>$file</a> Right click Save Target as... <br />";
}
if($fileType == "_vw_"){
$link2 = "http://www.domain.com/images/uploads/".$ref."/".$file;
$vwLink = "Wire-res link download: <a href='$link2'>$file</a> Right click Save Target as... <br />";
}
}
}
}
$text.="<br />".$vmLink.$vwLink;
closedir($handle);
}
/* */
$b = 0;
$fEmail = "noreply@domain.com";
$mail_attached = "";
$boundary = md5(uniqid(time(),1))."_xmail";
$add_header = "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"";
if (count($files)>0) {
for ($a=0;$a<count($files);$a++) {
if ($fp = fopen($files[$a],"rb")) {
$file_name = basename($files[$a]);
$content[$b] = fread($fp,filesize($files[$a]));
$mail_attached .= "--".$boundary."\r\n"
."Content-Type: image/jpeg; name=\"$file_name\"\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-Disposition: attachment; filename=\"$file_name\"\r\n\r\n"
.chunk_split(base64_encode($content[$b]))."\r\n";
$b++;
fclose($fp);
} else {
echo "none";
}
}
$mail_attached .= "--".$boundary." \r\n";
$mail_content = "--".$boundary."\r\n"
. "Content-Type: text/html; charset=iso-8859-1; format=flowed\r\n"
. "Content-Transfer-Encoding: 8bit\r\n\r\n"
. $text."\r\n\r\n".$mail_attached;
$ok = mail($to,$subject,$mail_content,"$add_header\r\n"."FROM:".$fEmail,"-fwebmaster@{$_SERVER['SERVER_NAME']}");
return true;
}else {
$sheaders = "MIME-Version: 1.0\r\n";
$sheaders .= "Content-type: text/html; charset=iso-8859-1\r\n";
$sheaders .= "From: $fEmail\r\n";
$ok = mail($to,$subject,$text,$sheaders,"-fwebmaster@{$_SERVER['SERVER_NAME']}");
return true;
}
}
This is not all my code. More a miss-mash of years of editing.
Any takers?
Attached is a screen grab of the email that comes through with the issue.