Commit: 7b21ef85bb3b00273c14eb415cefaebe036f3b17 Author: Anatol Belski <[email protected]> Fri, 6 Sep 2013 17:13:01 +0200 Parents: 55e7ad7ad9debd1a9da7f223d9768fb5afcfdc91 Branches: master
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=7b21ef85bb3b00273c14eb415cefaebe036f3b17 Log: implementation draft for mail with attachment Changed paths: M client/include/Tools.php Diff: diff --git a/client/include/Tools.php b/client/include/Tools.php index d86ac0b..e4068d2 100644 --- a/client/include/Tools.php +++ b/client/include/Tools.php @@ -333,11 +333,36 @@ function copy_r($from, $to) function xmail($from, $to, $subject, $text, array $attachment = array()) { - $header = array(); - $boundary = '-----=' . md5(uniqid(mt_rand(), 1)); + $header = $mail = array(); + $boundary = '--' . md5(uniqid(mt_rand(), 1)); $header[] = "MIME-Version: 1.0"; - $header[] = "Content-Type: multipart/mixed;"; - $header[] = "boundary=\"$boundary\""; + $header[] = "From: $from"; + + $mail[] = "Content-Type: multipart/mixed; boundary=\"$boundary\""; + $mail[] = $boundary; + $mail[] = "Content-Type: text/plain; charset=latin1"; + $mail[] = "Content-Transfer-Encoding: 7bit\r\n"; + $mail[] = "$text\r\n"; + $mail[] = $boundary; + + foreach($attachment as $att) { + $fname = basename($att); + $fsize = filesize($att); + if (function_exists('mime_content_type')) { + $mime_type = mime_content_type($att); + } else { + $mime_type = 'application/octet-stream'; + } + $raw = file_get_contents($att); + + $mail[] = "Content-Type: $mime_type; name=\"$fname\""; + $mail[] = "Content-Transfer-Encoding: base64"; + $mail[] = "Content-Disposition: attachment; filename=\"$fname\"; size=\"$fsize\"\r\n"; + $mail[] = chunk_split(base64_encode($raw)) . "\r\n"; + $mail[] = $boundary; + } + + return mail($to, $subject, implode("\r\n", $mail), implode("\r\n", $header)); } -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
