Good day, i have written code to send mail to email with an pdf attachment.The pdf is receive when it is send to a gmail account,but when it is send to an exchange mail account,it just looks as in the picture.A lot of nonsens.
my statement.pdf is in the folder mainfolder/fpdf
i have tried various options,but just can not get this to work.Any help is appreciated.
this is the code i am using
$filename="statement.pdf";
$subject= "Statement";
$recipient = "
[email protected],
[email protected]";
$email="
[email protected]";
//documentation for Output method here: http://www.fpdf.org/en/doc/output.htm
$attach_pdf_multipart = chunk_split( base64_encode( $pdf->Output( $filename, 'S' ) ) );
//define the receiver of the email
$to = "
[email protected],
[email protected]";
//define the subject of the email
$subject = 'Statement';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From:
[email protected]\r\nReply-To:
[email protected]";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$headers .= "\r\n";
$msg .= "Content-Type: application/octet-stream; name=\"statement.pdf\"\r\n";
$msg .= "\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: attachment\r\n";
$msg .= $attach_pdf_multipart . "\r\n";
$msg .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$msg .= "<p>This is text message from shohag</p>\r\n\r\n";
global $message;
$message = '';
$mail_sent = @mail( $to, $subject, $msg, $headers );
//@mail( $to1, $subject, $msg, $headers );
if(!empty($mail_sent)):
echo "Mail Has Been Send";
$message = "Statement sent succuessfully";
else:
echo "bad-----";
$message = "Error occured. Please try again.";
endif;