php - php5 mail bare line feed error -
i've inherited old ticketing system written in php5 'suddenly' has problems sending mails. i've never written line of php in life hope can me this.
for mails bounce mail couldn't delivered. contains invalid characters (bare line feeds). i've read far "\n" not standard conform , has replaced "\r\n". servers seem fix these , accept mail, don't , decline it.
a first attempt brute force replace instances of "\n" "\n\r" didn't work.
$email_subject = $subject; $headers = "from: ".$from; $semi_rand = md5(time()); $mime_boundary = "=_emailpart_" . $semi_rand . ""; $headers .= "\nmime-version: 1.0\n" . "content-type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"\n" . "x-mailer: supportsystem email-engine, build 0.1"; $email_message .= "this multi-part message in mime format.\n\n" . "--{$mime_boundary}\n" . "content-type:text/" . $text['type'] . "; charset=\"iso-8859-1\"\n" . "content-transfer-encoding: 7bit\n\n" . $text['content'] . "\n\n"; if (file_exists($datei)) { $idcount++; $fileatt = $datei; // path file $fileatt_type = "application/octet-stream"; // file type if ($dateiname) { $fileatt_name = $dateiname; // filename used file attachment }else{ $fileatt_name = basename($datei); } $file = fopen($fileatt,'rb'); $data = fread($file,filesize($fileatt)); fclose($file); $data = chunk_split(base64_encode($data)); $fileatt_contentid[$idcount]['name']=$datei; $fileatt_contentid[$idcount]['id']=md5(uniqid(rand(),true)) . "@" . $_server['server_name']; $email_message_anhang .= "--{$mime_boundary}\n" . "content-type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"content-disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "content-transfer-encoding: base64\n" . "content-id: <" . $fileatt_contentid[$idcount]['id'] . ">\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; unset($data); unset($file); unset($fileatt); unset($fileatt_type); unset($fileatt_name); } for($i=1;$i<=$idcount;$i++){ $email_message=str_replace($fileatt_contentid[$i]['name'],"cid:" . $fileatt_contentid[$i]['id'],$email_message); } $email_message.=$email_message_anhang; // add attachment $email_message.="--{$mime_boundary}--\n"; // finisch email $email_message=str_replace("\n","\r\n",$email_message); $headers=str_replace("\n","\r\n",$headers); $ok = @mail($to, $email_subject, $email_message, $headers);
Comments
Post a Comment