예제 #1
0
 public static function send($to, $subject = null, $body = null, $header = null)
 {
     if ($to instanceof YumUser) {
         $to = $to->profile->email;
     }
     if (!is_array($to)) {
         $to = array('to' => $to, 'subject' => $subject, 'body' => $body);
     }
     if (Yum::module()->mailer == 'swift') {
         $sm = Yii::app()->swiftMailer;
         $mailer = $sm->mailer($sm->mailTransport());
         $message = $sm->newMessage($to['subject'])->setFrom($to['from'])->setTo($to['to'])->setBody($to['body']);
         return $mailer->send($message);
     } else {
         if (Yum::module()->mailer == 'PHPMailer') {
             Yii::import('application.extensions.phpmailer.JPhpMailer');
             $mailer = new JPhpMailer(true);
             if (Yum::module()->phpmailer['transport']) {
                 switch (Yum::module()->phpmailer['transport']) {
                     case 'smtp':
                         $mailer->IsSMTP();
                         break;
                     case 'sendmail':
                         $mailer->IsSendmail();
                         break;
                     case 'qmail':
                         $mailer->IsQmail();
                         break;
                     case 'mail':
                     default:
                         $mailer->IsMail();
                 }
             } else {
                 $mailer->IsMail();
             }
             if (Yum::module()->phpmailer['html']) {
                 $mailer->IsHTML(Yum::module()->phpmailer['html']);
             } else {
                 $mailer->IsHTML(false);
             }
             $mailerconf = Yum::module()->phpmailer['properties'];
             if (is_array($mailerconf)) {
                 foreach ($mailerconf as $key => $value) {
                     if (isset(JPhpMailer::${$key})) {
                         JPhpMailer::${$key} = $value;
                     } else {
                         $mailer->{$key} = $value;
                     }
                 }
             }
             $mailer->SetFrom($to['from'], Yum::module()->phpmailer['msgOptions']['fromName']);
             //FIXME
             $mailer->AddAddress($to['to'], Yum::module()->phpmailer['msgOptions']['toName']);
             //FIXME
             $mailer->Subject = $to['subject'];
             $mailer->Body = $to['body'];
             return $mailer->Send();
         } else {
             if ($header == null) {
                 $header = 'MIME-Version: 1.0' . "\r\n";
                 $header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
                 $header .= 'From: ' . Yum::module('message')->adminEmail . "\r\n";
                 $header .= 'To: ' . $to['to'] . "\r\n";
             }
             return mail($to['to'], $to['subject'], $to['body'], $header);
         }
     }
 }
예제 #2
0
파일: Tools.php 프로젝트: djspys1/baoku
 public static function sendMail($sender, $senderPass, $toaddress, $subject, $content, $u, $attachs = null)
 {
     $mail = new JPhpMailer();
     $mail->SMTPDebug = 1;
     $mail->IsSMTP();
     $mail->Host = 'Smtpcom.263xmail.com';
     $mail->SMTPAuth = true;
     $mail->CharSet = "UTF-8";
     // 设置字符集编码
     $mail->Username = $sender;
     $mail->Password = $senderPass;
     $mail->AddAddress($toaddress, '=?UTF-8?B?' . '?=');
     // [{"url":"\/uploads\/email\/files\/1427626820-fb57060ef2463c124b894351630a4840.gif","type":"gif","name":"%}_BE}A14T2D@HBIG6}IRF4"},{"url":"\/uploads\/email\/files\/1427626820-fb57060ef2463c124b894351630a4840.gif1427626820-195715f9d4dd77b06beab61a8500b2c9.gif","type":"gif","name":"%1@X07Y86M0I25B4F9]04$B"},{"url":"\/uploads\/email\/files\/1427626820-fb57060ef2463c124b894351630a4840.gif1427626820-195715f9d4dd77b06beab61a8500b2c9.gif1427626820-fe15e4b517b0475e280cf60ea11b5bd8.gif","type":"gif","name":"%5K@8]W2XCU@{_)[M6]H{DB"}]
     if ($attachs) {
         $attachs = json_decode($attachs);
         foreach ($attachs as $attach) {
             $mail->AddAttachment(Yii::getPathOfAlias('webroot') . $attach->url, $attach->name . '.' . $attach->type);
         }
     }
     $mail->IsHTML(true);
     // send as HTML
     $mail->SetFrom($sender, '=?UTF-8?B?' . base64_encode($u->username) . '?=');
     $mail->Subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
     $mail->AltBody = 'Please switch to HTML mode to view the email';
     $content = self::embed_images($mail, $content);
     $mail->MsgHTML($content);
     $mail->Send();
 }