Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. <?php
  2. class Mail_hlp
  3. {
  4.     public function send_attach($server_path, $file_att_name, $to, $from, $subject)
  5.     {
  6.             $fileatt = $server_path;// Path to the file
  7.             $fileatt_type = "application/octet-stream"; // File Type
  8.             $fileatt_name = $file_att_name; // Filename that will be used for the file as the attachment
  9.  
  10.             $email_from = $from; // Who the email is from
  11.             $email_subject = $subject; // The Subject of the email
  12.             $email_message = "<b>You recieved a file</b>"; // Message that the email has in it
  13.  
  14.             $email_to = $to; // Who the email is too
  15.  
  16.             $headers = "From: ".$email_from;
  17.  
  18.  
  19.  
  20.             $semi_rand = md5(time());
  21.             $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  22.  
  23.             $headers .= "\nMIME-Version: 1.0\n" .
  24.             "Content-Type: multipart/mixed;\n" .
  25.             " boundary=\"{$mime_boundary}\"";
  26.  
  27.             $email_message .= "This is a multi-part message in MIME format.\n\n" .
  28.             "--{$mime_boundary}\n" .
  29.             "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  30.             "Content-Transfer-Encoding: 7bit\n\n" .
  31.             $email_message . "\n\n";
  32.  
  33.  
  34.  
  35.             /********************************************** First File ********************************************/
  36.  
  37.  
  38.             $fileatt = $fileatt = $server_path; // Path to the file
  39.             $fileatt_type = "application/octet-stream"; // File Type
  40.             $fileatt_name = $file_att_name; // Filename that will be used for the file as the attachment
  41.  
  42.             $file = fopen($fileatt,'rb');
  43.             $data = fread($file,filesize($fileatt));
  44.             fclose($file);
  45.  
  46.  
  47.             $data = chunk_split(base64_encode($data));
  48.  
  49.             $email_message .= "--{$mime_boundary}\n" .
  50.             "Content-Type: {$fileatt_type};\n" .
  51.             " name=\"{$fileatt_name}\"\n" .
  52.             //"Content-Disposition: attachment;\n" .
  53.             //" filename=\"{$fileatt_name}\"\n" .
  54.             "Content-Transfer-Encoding: base64\n\n" .
  55.             $data . "\n\n" .
  56.             "--{$mime_boundary}\n";
  57.             unset($data);
  58.             unset($file);
  59.             unset($fileatt);
  60.             unset($fileatt_type);
  61.             unset($fileatt_name);
  62.  
  63.  
  64.  
  65.             /********************************************** End of File Config ********************************************/
  66.  
  67.             // To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work!
  68.  
  69.  
  70.             $ok = @mail('sales@cle2perse.com', $email_subject, $email_message, $headers);
  71.  
  72.             /*if($ok) {
  73.             echo "<font face=verdana size=2>The file was successfully sent!</font>";
  74.             } else {
  75.             die("Sorry but the email could not be sent. Please go back and try again!");
  76.             }*/
  77.     }
  78. }
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement