com web/rmtools: implementation draft for mail with attachment: client/include/Tools.php
| From: | Stephen A. Zarkos | Date: | Fri, 06 Sep 2013 15:13:01 +0000 |
| Subject: | com web/rmtools: implementation draft for mail with attachment: client/include/Tools.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-16713@lists.php.net to get a copy of this message | ||
Commit: 7b21ef85bb3b00273c14eb415cefaebe036f3b17
Author: Anatol Belski <ab@php.net> 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));
}