0

I am trying to send a HTML email with a PDF attachment using mail, but I get this error:

Warning: mail(): Multiple or malformed newlines found in additional_header in filename on line 69

Is it possible to send attachments this way:

$file = "New CV - small.pdf";
$file_size = filesize($file);
$filename = "My CV";
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);

$uid = md5(uniqid(time()));

$content = chunk_split(base64_encode($content));

$email = format_email ($name, $company['name'], $ending, false, $link);

$headers = "From: Paul Ledger <route1designs@hotmail.co.uk>\r\n";
$headers .= "Reply-To: route1designs@hotmail.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= $subject."\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";


mail($email_to, $subject, $email, $headers);
Paul Ledger
  • 1,125
  • 4
  • 21
  • 46

0 Answers0