/** * * Mauro Cerone * * @todo read config from file */ public static function startSendOperation() { /** @var ConfigReader $conf */ $conf = ConfigReader::getInstance(); $mailToSend = StesiMailQuery::create()->filterByDeliveryStatus("0")->find(); foreach ($mailToSend as $mail) { try { /** @var StesiMail $conf */ $mailer = new PHPMailer(true); $mailer->isHTML(true); $mailer->SMTPAuth = true; $mailer->isSMTP(); $mailer->Username = $conf->getUsername(); $mailer->Password = $conf->getPassword(); $mailer->Host = $conf->getHost(); $mailer->Port = $conf->getPort(); $mailer->SMTPSecure = $conf->getSmtSecure(); $mailer->setFrom($mail->getFrom()); $mailer->Subject = $mail->getSubject(); $arrayA = explode(";", $mail->getA()); $arrayCC = explode(";", $mail->getCc()); foreach ($arrayA as $a) { if (!empty($a)) { $mailer->addAddress($a); } } foreach ($arrayCC as $cc) { if (!empty($cc)) { $mailer->addCC($cc); } } $mailer->msgHTML($mail->getContent()); $mailer->send(); $mail->setDeliveryStatus(1); } catch (\Exception $ex) { $mail->setDeliveryStatus(-1); $mail->setErrorMessage($ex->getMessage()); } finally { $mail->save(); } } }
/** * @return $this */ public function addCc() { $args = func_get_args(); isset($args[1]) ? $this->mail->addCC($args[0], $args[1]) : $this->mail->addCC($args[0]); return $this; }
private function addCCs() { $emailsToAdd = $this->options->getTo(); if (!empty($emailsToAdd)) { foreach ($this->options->getTo() as $to) { $this->mailClient->addCC($to); } } }