I found a script for sending email with attachment, it works great. But my problem is, that i want to send some text in body. But my HTML text is also like attachment!!! :(
$letter = "subor_".$kod.".pdf";
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="\r";
} else {
$eol="\n";
}
# File for Attachment
$f_name= dirname(__FILE__) . "/../files/pdf/".$sluzba_id."/".$letter;
chmod($f_name, 0777);
// use relative path OR ELSE big headaches. $letter is my file for attaching.
$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($f_name);
fclose($handle);
# To Email Address
$emailaddress=$email;
# Message Subject
$emailsubject="Predmet";
# Message Body
ob_start();
require("./form/email_priloha_pokec.php"); // i made a simple & pretty page for showing in the email
$body=ob_get_contents(); ob_end_clean();
# Common Headers
$headers_2 .= 'From: email@email.sk <email@email.sk>'.$eol;
$headers_2 .= 'Reply-To: Email <email@email.sk>'.$eol;
$headers_2 .= 'Return-Path: Email <email@email.sk>'.$eol; // these two to set reply address
$headers_2 .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers_2 .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers_2 .= 'MIME-Version: 1.0'.$eol;
$headers_2 .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=utf-8".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,'email@email.sk'); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers_2);
ini_restore(sendmail_from);


Sign In
Create Account

Back to top









