/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Funzione di libreria testata e stra-testata per invio di mail. * * @param $to * @param $from * @param $from_name * @param $subject * @param $message * @param $reply_to * @param $attachments * @param $cc * @param $bcc */ function send_email_advanced($to = null, $from, $from_name, $subject, $message, $reply_to, $attachments = false, $cc = null, $bcc = null) { $eol = "\n"; $headers = "From: " . $from_name . "<" . $from . ">".$eol; $log_dir="logs/email_log/"; $log_file=$log_dir."email_log_{$today}_{$from_name}.html"; if ($bcc != ''){ $headers .= "BCC: $bcc".$eol; } $headers .= "CC: $cc".$eol; $headers .= "Reply-To: " . $reply_to . "<" . $reply_to . ">".$eol; $headers .= "Return-Path: " . $from_name . "<" . $from . ">".$eol; //$headers .= "X-Mailer: PHP v" . phpversion (); $msg_txt = ""; $email_txt = $message; //$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $mime_boundary = $semi_rand; $headers .= "MIME-Version: 1.0".$eol."Content-Type: multipart/mixed;".$eol." boundary=\"$mime_boundary\"".$eol.$eol; $email_txt .= $msg_txt; $email_message .= "This is a multi-part message in MIME format.".$eol.$eol; $email_message .= "--$mime_boundary".$eol; $email_message .= "Content-Type:text/html; charset=\"iso-8859-1\"".$eol.$eol; $email_message .= $email_txt.$eol.$eol; if ($attachments != false) { $fileatt = $attachments [$i] ['src']; $fileatt_type = "application/octet-stream"; $fileatt_name = $attachments [$i] ['name']; $filetype=returnMIMEType($fileatt_name); // $email_message .= "Content-Type: ".mime_content_type($fileatt_name).";".$eol; $email_message .= "--$mime_boundary".$eol; $email_message .= "Content-Type: $filetype; name=\"$fileatt_name\"".$eol; $email_message .= "Content-Transfer-Encoding: base64".$eol; $email_message .= "Content-Disposition: attachment;".$eol; $email_message .= "filename=\"$fileatt_name\"".$eol.$eol; $email_message .= $data.$eol; } } } $email_message .= "--$mime_boundary--".$eol; $log="<p align=center>Email sended at $now</p> <li>to:$to</li> <li>headers:$headers</li> <li>oggetto:$subject</li> <li>testo:$message</li> <hr>"; $flag="w"; } else { $flag="a"; } // $log.=file_get_contents($log_dir); } /** * Funzione di libreria di appoggio alla funzione send_mail_advanced * * @param unknown_type $filename */ function returnMIMEType($filename){ case "js" : return "application/x-javascript"; case "json" : return "application/json"; case "jpg" : case "jpeg" : case "jpe" : return "image/jpg"; case "png" : case "gif" : case "bmp" : case "tiff" : case "css" : return "text/css"; case "xml" : return "application/xml"; case "doc" : case "docx" : return "application/msword"; case "xls" : case "xlt" : case "xlm" : case "xld" : case "xla" : case "xlc" : case "xlw" : case "xll" : return "application/vnd.ms-excel"; case "ppt" : case "pps" : return "application/vnd.ms-powerpoint"; case "rtf" : return "application/rtf"; case "pdf" : return "application/pdf"; case "html" : case "htm" : case "php" : return "text/html"; case "txt" : return "text/plain"; case "mpeg" : case "mpg" : case "mpe" : return "video/mpeg"; case "mp3" : return "audio/mpeg3"; case "wav" : return "audio/wav"; case "aiff" : case "aif" : return "audio/aiff"; case "avi" : return "video/msvideo"; case "wmv" : return "video/x-ms-wmv"; case "mov" : return "video/quicktime"; case "zip" : return "application/zip"; case "tar" : return "application/x-tar"; case "swf" : return "application/x-shockwave-flash"; default : } } }
URL: send_mail_advanced