Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- mail_advanced(
- array("Sender Name" => "sender@email.com"),
- array("user1@email.com","user2@gmail.com","user3@email.com"),
- "This is a subject",
- "This is an email body"
- );
- mail_attachments(
- array("Sender Name" => "sender@email.com"),
- array("user1@email.com","user2@gmail.com","user3@email.com"),
- "This is a subject",
- "This is an email body",
- array(
- "File1" => "/path/to/file1.ext",
- "File2" => "/path/to/file2.ext"
- )
- );
- */
- function mail_advanced($fromArray, $toArray, $subject, $message)
- {
- $to = implode(", ", $toArray);
- $headers = "";
- foreach($fromArray as $key => $value)
- {
- $headers .= "From: " . $key . " < ".$value." >" . "\r\n";
- $headers .= "X-Sender: " . $key . " < " . $value . " >" . "\r\n";
- $headers .= "Return-Path: " . $value . "\r\n";
- }
- $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
- $headers .= "X-Priority: 1" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- if(!mail($to,$subject,$message,$headers))
- {
- return false;
- }
- return true;
- }
- function mail_attachments($fromArray, $toArray, $subject, $message, $fileArray)
- {
- $to = implode(", ", $toArray);
- $semi_rand = md5(time());
- $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
- $headers = "";
- foreach($fromArray as $key => $value)
- {
- $headers .= "From: " . $key . " < ".$value." >" . "\r\n";
- $headers .= "X-Sender: " . $key . " < " . $value . " >" . "\r\n";
- $headers .= "Return-Path: " . $value . "\r\n";
- }
- $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
- $headers .= "X-Priority: 1" . "\r\n";
- $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
- $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
- foreach($fileArray as $filename => $filepath)
- {
- if(is_file($filepath))
- {
- $message .= "--{$mime_boundary}\n";
- $fp = @fopen($filepath,"rb");
- $filesize = @filesize($filepath);
- $data = @fread($fp,$filesize);
- @fclose($fp);
- $data = chunk_split(base64_encode($data));
- $message .= "Content-Type: application/octet-stream; name=\"".$filename."\"\n";
- $message .= "Content-Description: ".$filename."\n";
- $message .= "Content-Disposition: attachment;\n" . " filename=\"".$filename."\"; size=".$filesize.";\n";
- $message .= "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
- }
- }
- $message .= "--{$mime_boundary}--";
- if(!mail($to,$subject,$message,$headers))
- {
- return false;
- }
- return true;
- }
- ?>
Add Comment
Please, Sign In to add comment