1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  |         $target = "./".$HTTP_POST_FILES['attachment']['name'];
        $attach['name'] = $HTTP_POST_FILES['attachment']['name'];
        $attach['type'] = $HTTP_POST_FILES['attachment']['type'];
        copy($HTTP_POST_FILES['attachment']['tmp_name'],$target);
        unlink($HTTP_POST_FILES['attachment']['tmp_name']);
        
        $attachment = $mail->getFile($target);
        function getFile($filename)
        {
                $return = '';
                if ($fp = fopen($filename, 'rb')) {
                        while (!feof($fp)) {
                                $return .= fread($fp, 1024);
                        }
                        fclose($fp);
                        return $return;
                } else {
                        return false;
                }
        }
        function addAttachment($file, $name = '', $c_type, $encoding = 'base64')
        {
                $this->attachments[] = array(
                                                                        'body'                => $file,
                                                                        'name'                => $name,
                                                                        'c_type'        => $c_type,
                                                                        'encoding'        => $encoding
                                                                  );
        }
        $mail->addAttachment($attachment, $attach['name'], $attach['type']);
function send($recipients, $type = 'mail')
        {
                if (!defined('CRLF')) {
                        $this->setCrlf($type == 'mail' ? "\n" : "\r\n");
                }
                if (!$this->is_built) {
                        $this->buildMessage();
                }
                switch ($type) {
                        case 'mail':
                                $subject = '';
                                if (!empty($this->headers['Subject'])) {
                                        $subject = $this->_encodeHeader($this->headers['Subject'], $this->build_params['head_charset']);
                                        unset($this->headers['Subject']);
                                }
                                // Get flat representation of headers
                                foreach ($this->headers as $name => $value) {
                                        $headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
                                }
                                $to = $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
                                if (!empty($this->return_path)) {
                                        $result = mail($to, $subject, $this->output, implode(CRLF, $headers), '-f' . $this->return_path);
                                } else {
                                        $result = mail($to, $subject, $this->output, implode(CRLF, $headers));
                                }
                                
                                // Reset the subject in case mail is resent
                                if ($subject !== '') {
                                        $this->headers['Subject'] = $subject;
                                }
                                
                                // Return
                                return $result;
                                break;
                        case 'smtp':
                                require_once(dirname(__FILE__) . '/smtp.php');
                                require_once(dirname(__FILE__) . '/RFC822.php');
                                $smtp = &smtp::connect($this->smtp_params);
                                
                                // Parse recipients argument for internet addresses
                                foreach ($recipients as $recipient) {
                                        $addresses = Mail_RFC822::parseAddressList($recipient, $this->smtp_params['helo'], null, false);
                                        foreach ($addresses as $address) {
                                                $smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
                                        }
                                }
                                unset($addresses); // These are reused
                                unset($address);   // These are reused
                                // Get flat representation of headers, parsing
                                // Cc and Bcc as we go
                                foreach ($this->headers as $name => $value) {
                                        if ($name == 'Cc' OR $name == 'Bcc') {
                                                $addresses = Mail_RFC822::parseAddressList($value, $this->smtp_params['helo'], null, false);
                                                foreach ($addresses as $address) {
                                                        $smtp_recipients[] = sprintf('%s@%s', $address->mailbox, $address->host);
                                                }
                                        }
                                        if ($name == 'Bcc') {
                                                continue;
                                        }
                                        $headers[] = $name . ': ' . $this->_encodeHeader($value, $this->build_params['head_charset']);
                                }
                                // Add To header based on $recipients argument
                                $headers[] = 'To: ' . $this->_encodeHeader(implode(', ', $recipients), $this->build_params['head_charset']);
                                
                                // Add headers to send_params
                                $send_params['headers']    = $headers;
                                $send_params['recipients'] = array_values(array_unique($smtp_recipients));
                                $send_params['body']       = $this->output;
                                // Setup return path
                                if (isset($this->return_path)) {
                                        $send_params['from'] = $this->return_path;
                                } elseif (!empty($this->headers['From'])) {
                                        $from = Mail_RFC822::parseAddressList($this->headers['From']);
                                        $send_params['from'] = sprintf('%s@%s', $from[0]->mailbox, $from[0]->host);
                                } else {
                                        $send_params['from'] = 'postmaster@' . $this->smtp_params['helo'];
                                }
                                // Send it
                                if (!$smtp->send($send_params)) {
                                        $this->errors = $smtp->errors;
                                        return false;
                                }
                                return true;
                                break;
                }
        }
$result = $mail->send(array('lol@lol.nl')); |