305 |
} |
} |
306 |
} |
} |
307 |
|
|
|
|
|
|
|
|
|
/** |
|
|
* Envoie un mail avec piece jointe |
|
|
* |
|
|
* @param string $title Titre du mail |
|
|
* @param string $message Corps du mail |
|
|
* @param string $recipient Destinataire du mail |
|
|
* @param array $file Destinataire du mail |
|
|
* @access public |
|
|
* @return bool True si le mail est correctement envoye, false sinon. |
|
|
*/ |
|
|
public function sendMail($title, $message, $recipient, $file = array()) { |
|
|
|
|
|
@include_once "../php/phpmailer/class.phpmailer.php"; |
|
|
|
|
|
if (!class_exists("PHPMailer")) { |
|
|
$this->addToLog("sendMail(): !class_exists(\"PHPMailer\")", DEBUG_MODE); |
|
|
return false; |
|
|
} |
|
|
|
|
|
// |
|
|
$this->setMailConfig(); |
|
|
|
|
|
// |
|
|
if ($this->mail_config == false) { |
|
|
$this->addToLog("sendMail(): aucune configuration mail", DEBUG_MODE); |
|
|
return false; |
|
|
} |
|
|
|
|
|
// |
|
|
$mail = new PHPMailer(true); |
|
|
|
|
|
// |
|
|
$mail->IsSMTP(); |
|
|
|
|
|
$mail->SMTPAuth = true; // enable SMTP authentication |
|
|
$mail->SMTPSecure = "tls"; |
|
|
$mail->Username = $this->mail_config["mail_username"]; |
|
|
$mail->Password = $this->mail_config["mail_pass"]; |
|
|
if ($this->mail_config["mail_username"] == '') { |
|
|
$mail->SMTPAuth = false; |
|
|
} else { |
|
|
$mail->SMTPAuth = true; |
|
|
} |
|
|
$mail->Port = $this->mail_config["mail_port"]; |
|
|
$mail->Host = $this->mail_config["mail_host"]; |
|
|
$mail->AddReplyTo($this->mail_config["mail_from"], $this->mail_config["mail_from_name"]); |
|
|
$mail->From = $this->mail_config["mail_from"]; |
|
|
$mail->FromName = $this->mail_config["mail_from_name"]; |
|
|
foreach (explode(",",$recipient) as $adresse) { |
|
|
if (!$this->checkValidEmailAddress($adresse)) { |
|
|
$this->addToLog("sendMail(): courriel incorrect ".$adresse, DEBUG_MODE); |
|
|
return false; |
|
|
} else |
|
|
$mail->AddAddress(trim($adresse)); |
|
|
} |
|
|
$mail->IsHTML(true); |
|
|
|
|
|
// Corps du message |
|
|
$mail_body ="<html>"; |
|
|
$mail_body .= "<head><title>".$title."</title></head>"; |
|
|
$mail_body .= "<body>".$message."</body>"; |
|
|
$mail_body .= "</html>"; |
|
|
|
|
|
$mail->Subject = $title; |
|
|
$mail->MsgHTML($mail_body); |
|
|
foreach($file as $oneFile) { |
|
|
|
|
|
if($oneFile['stream']){ |
|
|
$mail->AddStringAttachment($oneFile['content'], $oneFile['title'], $oneFile['encoding'] = 'base64',$oneFile['type'] = 'application/octet-stream'); |
|
|
} else{ |
|
|
$mail->AddAttachment($oneFile['url']); |
|
|
} |
|
|
} |
|
|
// Envoie de l'email |
|
|
if ($mail->Send()) { |
|
|
return true; |
|
|
} else { |
|
|
$this->addToLog("sendMail(): ".$mail->ErrorInfo, DEBUG_MODE); |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
308 |
/** |
/** |
309 |
* |
* |
310 |
*/ |
*/ |