Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function send ($param) {
- if(!$this->tru->utility->checkKey($param, array("subject", "html"))){
- $this->tru->error->add(array(
- "type" => "email-send-fail",
- "data" => $param,
- "terminate" => false
- ));
- return false;
- } else {
- $param["html"] = str_replace("{\$title}", $param["subject"], $param["html"]);
- $plain = preg_replace("/<style(.+?)<\/style>/is","", $param["html"]);
- $param = $this->tru->apply($param, array(
- "server" => $this->tru->config->get("email.smtp.default"),
- "from" => $this->tru->config->get("email.from"),
- "fromname" => $this->tru->config->get("email.from-name"),
- "plain" => strip_tags(preg_replace('/<br\\\\s*?\\/??>/i', "\\n", $plain))
- ));
- if($this->tru->config->get("email.method") == 'smtp') {
- require_once($this->tru->config->get("root.path").$this->tru->config->get("email.path-to-mailer")."/class.phpmailer.php");
- require_once($this->tru->config->get("root.path").$this->tru->config->get("email.path-to-mailer")."/class.smtp.php");
- require_once($this->tru->config->get("root.path").$this->tru->config->get("email.path-to-mailer")."/phpmailer.lang-en.php");
- if (count($this->replyto) < 1) {
- $this->replyto[]["email"] = $this->tru->config->get("email.reply-to");
- }
- $this->mailer = new PHPMailer();
- $this->mailer->IsSMTP();
- $this->mailer->SMTPDebug = $this->tru->config->get("email.debug");
- $this->mailer->SMTPKeepAlive = true;
- $this->mailer->SingleTo = true;
- $smtpConfig = $this->tru->config->get("email.smtp.".$param["server"]);
- $this->mailer->SMTPAuth = $smtpConfig["auth"];
- $this->mailer->SMTPSecure = $smtpConfig["secure"];//$this->tru->config->get("email.smtp.secure");
- $this->mailer->Host = $smtpConfig["host"];//$this->tru->config->get("email.smtp.host");
- $this->mailer->Port = $smtpConfig["port"];//$this->tru->config->get("email.smtp.port");
- $this->mailer->Username = $smtpConfig["username"];//$this->tru->config->get("email.smtp.username");
- $this->mailer->Password = $smtpConfig["password"];//$this->tru->config->get("email.smtp.password");
- $this->mailer->WordWrap = 0;
- $this->mailer->From = $param['from'];
- $this->mailer->FromName = $param['fromname'];
- $this->mailer->Subject = $param['subject'];
- $this->mailer->Body = $param['html'];
- $this->mailer->AltBody = $param['plain'];
- foreach($this->recipients as $key => $data){
- if(array_key_exists("name", $data)){
- $this->mailer->AddAddress($data['email'], $data['name']);
- } else {
- $this->mailer->AddAddress($data['email']);
- }
- }
- foreach($this->attachments as $key => $data){
- if(is_array($data) && array_key_exists("name", $data)){
- $this->mailer->AddAttachment($data['path'], $data['name']);
- } else {
- $this->mailer->AddAttachment($data['path']);
- }
- }
- foreach($this->replyto as $key => $data){
- if(is_array($data) && array_key_exists("name", $data)){
- $this->mailer->AddReplyTo($data['email'], $data['name']);
- } else {
- $this->mailer->AddReplyTo($data['email']);
- }
- }
- $this->mailer->IsHTML(true);
- if($this->mailer->Send()){
- $this->tru->log->add(array(
- "type" => "email-send",
- "data" => array(
- "subject" => $param['subject'],
- "to" => $this->recipients,
- "attachmentList" => $this->attachments
- )));
- $this->closeSMTP();
- return true;
- } else {
- $param["recipientList"] = $this->recipients;
- $param["attachmentList"] = $this->attachments;
- $this->tru->error->add(array(
- "type" => "email-send-fail",
- "data" => array(
- "paramList" => $param,
- "mailerError" => $this->mailer->ErrorInfo
- ),
- "terminate" => false
- ));
- $this->closeSMTP();
- return false;
- }
- } else {
- $this->tru->error->add(array(
- "type" => "invalid-mail-method",
- "data" => array(
- "param" => $param,
- "method" => $this->tru->config->get("email.method")
- ),
- "terminate" => false
- ));
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement