I am generating pdf and sent it through email as attachment the code is given below for this i skipped some code for generating pdf (not needed). Please check the code:
//pdf generated not given avobe code of how it comes
$pdfdoc = $pdf->Output("confirmation-".$client_code.".pdf", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
$to = $mail_to;
$from = "From: <info@ksilbd.com>";
$subject = "Here is your attachment";
$mainMessage = "BUY/SALE CONFIRMATION";
$fileatt = $attachment;
$fileatttype = "application/pdf";
$fileattname = "confirmation-".$client_code.".pdf";
$headers = "From: $from";
$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "
MIME-Version: 1.0
" .
"Content-Type: multipart/mixed;
" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.
" .
"-{$mime_boundary}
" .
"Content-Type: text/plain; charset=\"iso-8859-1
" .
"Content-Transfer-Encoding: 7bit
" .
$mainMessage . "
";
//base_64
//encoding used
//to encode data
$data = chunk_split(base64_encode($data));
//message
//concat the
//message
$message .= "--{$mime_boundary}
" .
"Content-Type: {$fileatttype};
" .
" name=\"{$fileattname}\"
" .
"Content-Disposition: attachment;
" .
" filename=\"{$fileattname}\"
" .
"Content-Transfer-Encoding: base64
" .
$data . "
" .
"-{$mime_boundary}-
";
// Send the email
if(mail($to, $subject, $message, $headers)) {
echo "EMAIL SENT SUCCESSFUL.";
}
else {
echo "There was an error sending the mail.";
The message showed email sent successful and i got email too but i failed to open the attached pdf file with the mail .... please check the problem
You may use "phpmailer". Download the PHPMailer script from here: http://github.com/PHPMailer/PHPMailer and Enjoy it.