I'm not receiving emails when using the following function. Is there another method that works or that I can test?
<?php
$data = ob_get_clean();
require_once(dirname(__FILE__).'/make-pdf.php');
require_once(dirname(__FILE__).'/attach-mail.php');
$pdf = make_pdf($data);
$filename = 'confirmation_'.date('Ymd_his').'.pdf';
$to = $_POST['admin_email'];
$from = 'my@email.com';
$subject = "Enquiry";
mail_attachment($filename, $pdf, $to, $from, $subject, $message);
echo $data;
} ?>
attach-mail.php
<?php
function mail_attachment($filename, $data, $mailto, $from_mail, $subject, $message) {
$file_size = strlen($data);
$data = chunk_split(base64_encode($data));
$uid = md5(uniqid(time()));
$header = "From: ".$from_mail."\r\n";
$header .= 'Cc: my-other@email.com' . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/html; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $data."\r\n\r\n";
$header .= "--".$uid."--";
mail($mailto, $subject, "", $header);
}
?>