PHP_MAIL FÜGGVÉNY

/* //============================================= // Példák a használatára: //============================================= // _ci_mail_sender($to, $body, $subject, $fromaddress, $fromname, $attachments=NULL, $cc=NULL, $bcc=NULL) $success = _ci_mail_sender("oda@.hu", "Üzenet szövege

Aláírás", "Tárgy", "innen@.hu", "Küldo neve", array("fájl1.txt", "fájl2.xls")); $success = _ci_mail_sender("oda@.hu", "Üzenet szövege

Aláírás", "Tárgy", "innen@.hu", "Küldo neve", "fájl1.txt", "cc@.hu"); $success = _ci_mail_sender("oda@.hu", "Üzenet szövege

Aláírás", "Tárgy", "innen@.hu", "Küldo neve", "fájl1.txt", "cc@.hu, cc2@.hu", "bcc@.hu"); $success = _ci_mail_sender("oda@.hu, oda2@.hu", "Üzenet szövege

Aláírás", "Tárgy", "innen@.hu", "Küldo neve", "fájl1.txt", array("cc@.hu", "cc2@.hu"), array("bcc@.hu")); */ //============================================= //

Szöveg kódolása - email-ekben használatos a fejlécben function _ci_quoted_printable_encode($string, $encoding='UTF-8')

{ // use this function with headers, not with the email body as it misses word wrapping $len = strlen($string); $result = ''; $enc = false; for($i=0;$i<$len;++$i) { $c = $string[$i]; if (ctype_alpha($c)) $result.=$c; else if ($c==' ') { $result.='_'; $enc = true; }

else { $result.=sprintf("=%02X", ord($c)); $enc = true; } } //L: so spam agents won't mark your email with QP_EXCESS if (!$enc) return $string; return '=?'.$encoding.'?q?'.$result.'?='; }; //=============================================

// E-mail küldo rutin function _ci_mail_sender($to, $body, $subject, $fromaddress, $fromname, $attachments=NULL, $cc=NULL, $bcc=NULL) { $filenames = array();

// Skalárból tömböt készít if ($cc && !is_array($cc )) $cc = array($cc ); if ($bcc && !is_array($bcc)) $bcc = array($bcc); if ($attachments && !is_array($attachments)) $attachments = array($attachments);

$eol="\r\n"; $mime_boundary=md5(time()); $fromname = _ci_quoted_printable_encode($fromname); $subject = _ci_quoted_printable_encode($subject);

# Common Headers $headers .= "From: ".$fromname."<".$fromaddress.">".$eol; if ($cc) $headers .= "Cc: ".implode(", ", $cc).$eol; if ($bcc) $headers .= "Bcc: ".implode(", ", $bcc).$eol; $headers .= "Reply-To: ".$fromname."<".$fromaddress.">"

.$eol; $headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol; // these two to set reply address $headers .= "Message-ID: <".time()."-".$fromaddress.">"

.$eol; $headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters # Boundry for marking the split & Multitype Headers $headers .= 'MIME-Version: 1.0'.$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\""

.$eol.$eol; # Open the first part of the mail $msg = "--".$mime_boundary.$eol; $htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section # Setup for text OR html - $msg .= "Content-Type: multipart/alternative;

boundary=\"".$htmlalt_mime_boundary."\"".$eol.$eol; # Text Version $msg .= "--".$htmlalt_mime_boundary.$eol; $msg .= "Content-Type: text/plain; charset=utf-8".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= strip_tags(str_replace("


", "\n", substr($body, (strpos($body, " ")+6)))).$eol.$eol; # HTML Version $msg .= "--".$htmlalt_mime_boundary.$eol; $msg .= "Content-Type: text/html; charset=utf-8".$eol; $msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol; $msg .= $body.$eol.$eol; //close the html/plain text alternate portion $msg

.= "--".$htmlalt_mime_boundary."--".$eol.$eol; if ($attachments !== NULL) { for($i=0; $i < count($attachments); $i++) { if (is_file($attachments[$i])) { # File for Attachment //

$file_name = substr($attachments[$i]["file"], (strrpos($attachments[$i]["file"], "/")+1)); $file_path = $attachments[$i]; $file_name = basename($file_path); $handle=fopen($file_path, 'rb'); $f_contents=fread($handle, filesize($file_path));

$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode(); $f_type=filetype($file_path); fclose($handle);

# Attachment $msg .= "--".$mime_boundary.$eol; $msg .= "Content-Type: ".mime_content_type($file_path)."; name=\"".$file_name."\""

.$eol; $msg .= "Content-Transfer-Encoding: base64".$eol; $msg .= "Content-Description: ".$file_name.$eol; // !! This next line needs TWO end of lines !! IMPORTANT !!

$msg .= "Content-Disposition: attachment; filename=\"".$file_name."\"".$eol.$eol; $msg .= $f_contents.$eol.$eol; $filenames[] = $file_name; } } }; # Finished $msg .= "--".$mime_boundary."--

".$eol.$eol; // finish with two eol's for better security. see Injection. # SEND THE EMAIL ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !

$mail_sent = mail($to, $subject, $msg, $headers); $f = implode(", ", $filenames); if ($mail_sent) { if ($filenames == array()) { // LOG: "Email küldése a(z) $to címre, de nem volt fájl melléklet" }

else { // LOG: "A(z) $f fájl(ok) küldése a(z) $to címre" }; } else { // LOG: "Email küldése a(z) $to címre - fájlok: $f" }; ini_restore(sendmail_from); return $mail_sent; };