from}" for the Return-Path protected $phpmailer; //!< PHPMailer object; protected $blind_copy; //!< email of blind copy (list of emails separated by comma) protected $reply_to; //!< reply to function __construct() { $this->format='PLAIN'; $this->supplemental_header=""; $this->supplemental_param=MAIL_EXTRA_PARAM; $this->phpmailer = new PHPMailer; $this->phpmailer->CharSet = PHPMailer::CHARSET_UTF8; //$this->phpmailer->SMTPDebug = SMTP::DEBUG_CLIENT; $this->phpmailer->SMTPDebug = SMTP::DEBUG_OFF; $this->phpmailer->isSendmail(true); $this->phpmailer->XMailer = "noalyss-email"; $this->phpmailer->Host = "localhost"; $this->phpmailer->Port = "25"; $this->phpmailer->Username = ""; $this->phpmailer->Password = ""; $this->phpmailer->SMTPAuth = false; $this->afile=[]; } public function getMailto() { return $this->mailto; } public function getBlindCopy() { return $this->blind_copy; } public function getReplyTo() { return $this->reply_to; } public function setMailto($mailto) { $this->mailto = $mailto; return $this; } public function setBlindCopy($blind_copy) { $this->blind_copy = $blind_copy; return $this; } public function setReplyTo($reply_to) { $this->reply_to = $reply_to; return $this; } public function getSupplemental_param() { return $this->supplemental_param; } public function setSupplemental_param($supplemental_param) { $this->supplemental_param = $supplemental_param; return $this; } public function getPhpmailer() { return $this->phpmailer; } public function setPhpmailer($phpmailer) { $this->phpmailer = $phpmailer; return $this; } public function getSupplemental_header() { return $this->supplemental_header; } public function setSupplemental_header($supplemental_header) { $this->supplemental_header = $supplemental_header; return $this; } public function get_format() { return $this->format; } /** * @brief format is either HTML or PLAIN * @param type $format HTML or PLAIN * @return Sendmail_Core */ public function set_format($format) { if ( in_array($format,['PLAIN','HTML'] ) == false) { throw new \Exception('SC64 : unknow format '); } $this->format = $format; return $this; } /** * set the from * @param $p_from has the form name */ function set_from($p_from) { $this->from = $p_from; } /** * * @param $p_subject set the subject */ function set_subject($p_subject) { $this->subject = $p_subject; } /** * set the recipient * @param type $p_mailto has the form name */ function mailto($p_mailto) { $this->mailto = $p_mailto; } /** * @brief body of the message (utf8) * @param type $p_message */ function set_message($p_message) { // $this->message =wordwrap($p_message,70,"\r\n"); $this->message =$p_message; } /** *@brief Add file to the message * @param FileToSend $file file to add to the message */ function add_file(FileToSend $file) { $this->afile[] = $file; } /** * @brief verify that the message is ready to go * @throws Exception */ function verify() { $array = explode(",", "from,subject,mailto,message"); for ($i = 0; $i < count($array); $i++) { $name = $array[$i]; if (trim($this->$name??"") == "") { throw new Exception( sprintf(_("%s est vide"),$name),EXC_INVALID); } } } /** * * @brief Function to override if supplemental header are needed * @return string */ function add_supplemental_header() { return $this->supplemental_header; } /** *@brief create the message before sending */ function compose() { $this->phpmailer->setFrom($this->from); if ( $this->format == "HTML") { $this->phpmailer->Body = $this->message; $this->phpmailer->AltBody = \strip_tags($this->message); $this->phpmailer->isHTML(true); } else { $this->phpmailer->Body = $this->message; $this->phpmailer->isHTML(false); } $this->phpmailer->Subject = $this->subject; $nb_file=count($this->afile); for ($i=0;$i<$nb_file;$i++) { $this->phpmailer->addAttachment($this->afile[$i]->full_name); } $a_email = explode(',', $this->mailto); foreach ($a_email as $item) { $this->phpmailer->addAddress($item); } $a_blind_copy=explode(",",$this->blind_copy??""); $nb_blind_copy=count($a_blind_copy); for ($i=0;$i<$nb_blind_copy;$i++) { $this->phpmailer->addBCC($a_blind_copy[$i]); } if ( ! empty ($this->reply_to)) { $this->phpmailer->addReplyTo($this->reply_to); } $this->phpmailer->preSend(); } /** *@brief Send email * @throws Exception */ function send() { $this->phpmailer->send(); } }