I've ran into some problems with mail() in PHP. When sending my mail, it tells me the headers contains malformatted newlines. I've read this question, and it didn't solve my problem. I'm also aware that I can't use \r\r
, \r\0
, \r\n\r\n
, \n\n
, or \n\0
, which I have not. But where's the problem then? I can't figure out. Thanks for your time.
function mail_attachment($filename, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file_size = filesize($filename);
$handle = fopen($filename, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n";
$header .= $content."\r\n";
$header .= "--".$uid."--";
mail($mailto, $subject, $message, $header)
}
mail_attachment("invoice/0.pdf", "customer@customer.com", "noreply@mattronic.dk", "Mattronic", "reply@mattronic.dk", "Invoice", "Describing text");