I am using the below code and it's working. However the attached code does not work, and sending mail failed. Could it be to do with the wrong header?
Here the $htmlTable
variable is used for collecting form post value and coverting it to pdf using the html to pdf function.
But the mail is not sent with pdf.
$pdf->WriteHTML2("<br><br><br>$htmlTable");
$pdf->SetFont('Arial','B',6);
//Create PDF file with data
$semi_rand = md5(time());
$pdf1 = $htmlTable;
$file = $semi_rand . ".pdf";
$handle = fopen($file, 'w+');
fwrite($handle, $pdf);
fclose($handle);
// Additional headers
$subject = "User Form";
$content = chunk_split(file_get_contents($file));
$uid = md5(uniqid(time())); //unique identifier
//standard mail headers
$header = "From: ".$from."\r\n";
$header .= "Reply-To: ".$_POST['email']. "\r\n";
$header .= "MIME-Version: 1.0\r\n";
//declare multiple kinds of email (plain text + attch)
$header .="Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .="This is a multi-part message in MIME format.\r\n";
//plain txt part
//$header .= "--".$uid."\r\n";
// $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
// $header .= "Content-Transfer-Encoding: bit\r\n\r\n";
//$header .= 'sample'. "\r\n\r\n";
//attch part
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$file."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file."\"\r\n\r\n";
$header .= $content."\r\n\r\n"; //chucked up 64 encoded attch
$success = mail($to,$subject,'PFA',$header);
if (!$success) {
echo "Mail to " . $to . " failed .";
}else {
echo "Success : Mail was send to " . $to ;
print_r ($header);
}