Advertisement
Guest User

Untitled

a guest
May 17th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.21 KB | None | 0 0
  1. function send ($param) {
  2.         if(!$this->tru->utility->checkKey($param, array("subject", "html"))){
  3.             $this->tru->error->add(array(
  4.                 "type" => "email-send-fail",
  5.                 "data" => $param,
  6.                 "terminate" => false
  7.             ));        
  8.             return false;
  9.         } else {
  10.             $param["html"] = str_replace("{\$title}", $param["subject"], $param["html"]);
  11.            
  12.             $plain = preg_replace("/<style(.+?)<\/style>/is","", $param["html"]);
  13.             $param = $this->tru->apply($param, array(
  14.                 "server" => $this->tru->config->get("email.smtp.default"),
  15.                 "from" => $this->tru->config->get("email.from"),
  16.                 "fromname" => $this->tru->config->get("email.from-name"),
  17.                 "plain" => strip_tags(preg_replace('/<br\\\\s*?\\/??>/i', "\\n", $plain))
  18.             ));
  19.                
  20.             if($this->tru->config->get("email.method") == 'smtp') {
  21.                 require_once($this->tru->config->get("root.path").$this->tru->config->get("email.path-to-mailer")."/class.phpmailer.php");
  22.                 require_once($this->tru->config->get("root.path").$this->tru->config->get("email.path-to-mailer")."/class.smtp.php");
  23.                 require_once($this->tru->config->get("root.path").$this->tru->config->get("email.path-to-mailer")."/phpmailer.lang-en.php");
  24.                
  25.                 if (count($this->replyto) < 1) {
  26.                     $this->replyto[]["email"] = $this->tru->config->get("email.reply-to");
  27.                 }
  28.                
  29.                 $this->mailer = new PHPMailer();
  30.                 $this->mailer->IsSMTP();
  31.                 $this->mailer->SMTPDebug = $this->tru->config->get("email.debug");
  32.    
  33.                 $this->mailer->SMTPKeepAlive = true;
  34.                 $this->mailer->SingleTo = true;
  35.                
  36.                 $smtpConfig = $this->tru->config->get("email.smtp.".$param["server"]);
  37.                
  38.                 $this->mailer->SMTPAuth = $smtpConfig["auth"];
  39.                 $this->mailer->SMTPSecure = $smtpConfig["secure"];//$this->tru->config->get("email.smtp.secure");      
  40.                 $this->mailer->Host = $smtpConfig["host"];//$this->tru->config->get("email.smtp.host");  
  41.                 $this->mailer->Port = $smtpConfig["port"];//$this->tru->config->get("email.smtp.port");
  42.                
  43.                 $this->mailer->Username = $smtpConfig["username"];//$this->tru->config->get("email.smtp.username");
  44.                 $this->mailer->Password = $smtpConfig["password"];//$this->tru->config->get("email.smtp.password");            
  45.                
  46.                 $this->mailer->WordWrap = 0;
  47.                
  48.                 $this->mailer->From = $param['from'];
  49.                 $this->mailer->FromName = $param['fromname'];
  50.                 $this->mailer->Subject = $param['subject'];
  51.                 $this->mailer->Body = $param['html'];
  52.                 $this->mailer->AltBody = $param['plain'];
  53.            
  54.                 foreach($this->recipients as $key => $data){
  55.                     if(array_key_exists("name", $data)){
  56.                         $this->mailer->AddAddress($data['email'], $data['name']);
  57.                     } else {
  58.                         $this->mailer->AddAddress($data['email']);
  59.                     }
  60.                 }
  61.                
  62.                 foreach($this->attachments as $key => $data){
  63.                     if(is_array($data) && array_key_exists("name", $data)){
  64.                         $this->mailer->AddAttachment($data['path'], $data['name']);
  65.                     } else {
  66.                         $this->mailer->AddAttachment($data['path']);
  67.                     }
  68.                 }
  69.                
  70.                 foreach($this->replyto as $key => $data){
  71.                     if(is_array($data) && array_key_exists("name", $data)){
  72.                         $this->mailer->AddReplyTo($data['email'], $data['name']);
  73.                     } else {
  74.                         $this->mailer->AddReplyTo($data['email']);
  75.                     }
  76.                 }
  77.                
  78.                 $this->mailer->IsHTML(true);
  79.                
  80.                 if($this->mailer->Send()){
  81.                     $this->tru->log->add(array(
  82.                         "type" => "email-send",
  83.                         "data" => array(
  84.                                     "subject" => $param['subject'],
  85.                                     "to" => $this->recipients,
  86.                                     "attachmentList" => $this->attachments
  87.                     )));
  88.                    
  89.                     $this->closeSMTP();
  90.                    
  91.                     return true;
  92.                 } else {
  93.                     $param["recipientList"] = $this->recipients;
  94.                     $param["attachmentList"] = $this->attachments;
  95.                    
  96.                     $this->tru->error->add(array(
  97.                         "type" => "email-send-fail",
  98.                         "data" => array(
  99.                             "paramList" => $param,
  100.                             "mailerError" => $this->mailer->ErrorInfo
  101.                             ),
  102.                         "terminate" => false
  103.                     ));
  104.                    
  105.                     $this->closeSMTP();
  106.                    
  107.                     return false;
  108.                 }
  109.             } else {
  110.                 $this->tru->error->add(array(
  111.                     "type" => "invalid-mail-method",
  112.                     "data" => array(
  113.                             "param" => $param,
  114.                             "method" => $this->tru->config->get("email.method")
  115.                             ),
  116.                     "terminate" => false
  117.                 ));    
  118.                 return false;
  119.             }
  120.         }
  121.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement