Hello,
I want to attach a PDF to an email. I am looking for the minimum amount of code to do this. What is the minimum required to send a PDF? Do you have the code?
Here is what I have but it is not working:
$emailaddress="me@hotmail.com";
$emailsubject="Heres An Email with a PDF ".date("Y/m/d H:i:s");
$eol="\r\n";
$f_name=$_GET['id'].".pdf";
$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents));
$f_type=filetype($f_name);
fclose($handle);
$headers.="From: Server <onlineshop@domain.co.uk>".$eol;
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "The file is attached.";
Attachment
$msg .= "--".$mime_boundary.$eol;
$headers .= "Content-Type: application/pdf; name=\"".$f_name."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment; filename=\"".$f_name."\"".$eol.$eol;
$headers .= $f_contents.$eol.$eol;
mail($emailaddress, $emailsubject, $msg, $headers);