stuppid_bot

Отправка писем с аттачами

May 2nd, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2.  
  3. $boundary = uniqid();
  4. $headers  = "Mime-Version: 1.0\r\n";
  5. $headers .= "From: noreply@" . $_SERVER['HTTP_HOST'] . "\r\n";
  6. $headers .= "Reply-To: =?UTF-8?B?" . base64_encode($_POST['name']) . "?= <" . $_POST['email'] . ">\r\n";
  7. $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"";
  8. $body  = "--$boundary\r\n";
  9. $body .= "Content-Type: text/plain; charset=UTF-8\r\n";
  10. $body .= "Content-Transfer-Encoding: binary\r\n\r\n";
  11. $body .= $_POST['message'];
  12.  
  13. if (isset($_FILES['attachment'])) {
  14.     $body .= "\r\n";
  15.    
  16.     for ($i = 0, $c = count($_FILES['attachment']['name']); $i < $c; ++$i) {
  17.         $body .= "--$boundary\r\n";
  18.         $body .= "Content-Type: " . $_FILES['attachment']['type'][$i] . "; name=\"=?UTF-8?B?" . base64_encode($_FILES['attachment']['name'][$i]) . "?=\"\r\n";
  19.         $body .= "Content-Disposition: attachment\r\n";
  20.         $body .= "Content-Transfer-Encoding: base64\r\n\r\n";      
  21.         $body .= base64_encode( file_get_contents($_FILES['attachment']['tmp_name'][$i]) );
  22.         $body .= "\r\n";      
  23.     }
  24.    
  25.     $body .= "--$boundary--";
  26. }
  27.  
  28. mail($to, '=?UTF-8?B?' . base64_encode($_POST['subject']) . '?=', $body, $headers);
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment