예제 #1
0
파일: mailer.php 프로젝트: Kervinou/OBM
 protected function create($method_name, $args)
 {
     $mail = new SMail($this->date);
     
     if (is_array($this->from)) $mail->set_from($this->from[0], $this->from[1]);
     else $mail->set_from($this->from);
     
     if (!is_array($this->recipients)) $this->recipients = array($this->recipients);
     foreach ($this->recipients as $to) {
         if (is_array($to)) $mail->add_to($to[0], $to[1]);
         else $mail->add_to($to);
     }
     
     $mail->set_subject($this->subject);
     
     if (is_array($this->body)) {
         $template = $this->get_template_name($method_name);
         if (file_exists($this->get_template_path($template.'.plain')))
             $mail->set_text($this->render($template.'.plain', $this->body));
         if (file_exists($this->get_template_path($template.'.html')))
             $mail->set_html_text($this->render($template.'.html', $this->body));
     } elseif (is_string($this->body) && !empty($this->body)) {
         $mail->set_text($this->body);
     }
     
     foreach ($this->parts as $p) {
         $p = array_merge(self::$part_defaults, $p);
         $mail->add_part($p['content'], $p['content_type'], $p['encoding'], $p['charset']);
     }
     
     foreach ($this->attachments as $a) {
         $a = array_merge(self::$attachment_defaults, $a);
         $mail->add_attachment($a['content'], $a['filename'], $a['content_type'], $a['encoding']);
     }
     
     $this->reset();
     
     return $mail;
 }
예제 #2
0
파일: MailTest.php 프로젝트: Kervinou/OBM
    public function test_add_attachment_to_multipart_message()
    {
        $message = <<<EOT
Date: Fri, 13 Feb 09 15:47:25 +0100
MIME-Version: 1.0
To: John Doe <*****@*****.**>
Content-Type: multipart/mixed; boundary="c67476988f320ca04d61815bcfd14361"

This is a multi-part message in MIME format.
--c67476988f320ca04d61815bcfd14361
Content-Type: multipart/alternative; boundary="c67476988f320ca04d61815bcfd14360"

This is a multi-part message in MIME format.
--c67476988f320ca04d61815bcfd14360
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit

test
--c67476988f320ca04d61815bcfd14360
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 8bit

<b>test</b>
--c67476988f320ca04d61815bcfd14360--
--c67476988f320ca04d61815bcfd14361
Content-Type: image/png; name="hello.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="hello.png"

iVBORw0KGgoAAAANSUhEUgAAAAYAAAAFCAYAAABmWJ3mAAAAAXNSR0IArs4c6QAAAAZiS0dE
AP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAIBJREFUCNc9yK8OQWEcx+HPiyCb
JtjciKaZILgARTRXwfQTXIVGM03xZwLZtHN2zpiZ2fu+v6/miY+b7EYyRcwMJMo4us0+lWgB
WcQJEPRaA9qNDqxuS12Ks8bboTb3tSQpRC+e34ckKf9k/0z2U5WS04y3f1Gr1jEZi8Oca3rk
B3WXTGfs7Y8kAAAAAElFTkSuQmCC
--c67476988f320ca04d61815bcfd14361--
EOT;
        $mp = new SMimeMultipart();
        $mp->set_boundary('c67476988f320ca04d61815bcfd14360');
        $mp->add_part(new SMimePart('test'));
        $mp->add_part(new SMimePart('<b>test</b>', 'text/html'));
        $mail = new SMail($this->date);
        $mail->add_to('*****@*****.**', 'John Doe');
        $mail->set_content($mp);
        $mail->add_attachment(file_get_contents(dirname(__FILE__).'/files/image.png'), 'hello.png', 'image/png');
        $mail->set_boundary('c67476988f320ca04d61815bcfd14361');
        $this->assertEquals($message, (string) $mail);
    }