getEmailInfo($email); } private function getEmailInfo($email = false) { $this->from_user = $email ? $email['from_user'] : false; $this->from_email = $email ? $email['from_email'] : false; $this->to_user = $email ? $email['to_user'] : false; $this->to_email = $email ? $email['to_email'] : false; $this->subject = $email ? $email['subject'] : false; $this->message = $email ? $email['message'] : false; // $this->headers = []; // $this->headers[] = 'MIME-Version: 1.0'; // $this->headers[] = 'Content-type: text/html; charset=iso-8859-1'; // $this->headers[] = 'Content-Type: text/plain; charset=utf-8'; // En-tĂȘtes additionnels // $this->headers[] = 'To: ' . $this->to; // $this->headers[] = 'From: ' . $this->from_user . '<' . $this->from_email . '>'; // $this->headers[] = 'Reply-To: ' . $this->from; // $this->headers[] = 'X-Mailer: PHP/' . phpversion(); } public function send($email = false) { $result = [ 'success' => False, 'error' => False, 'message' => [] ]; if ($email) { $this->getEmailInfo($email); } // Envoi // $success = mail($this->to, $this->subject, $this->message, implode("\r\n", $this->headers)); // if (!$success) { // $result['error'] = error_get_last()['message']; // } else { // $result['success'] = True; // } $mail = new PHPMailer; $mail->isSMTP(); $mail->Host = 'smtp.georchestra-smtp'; $mail->SMTPAuth = false; $mail->Port = 25; $mail->setFrom($this->from_email, $this->from_user); $mail->addReplyTo($this->from_email, $this->from_user); $mail->addAddress($this->to_email, $this->to_user); $mail->Subject = $this->subject; $mail->isHTML(true); // $mail->msgHTML(file_get_contents('test_phpmailer_email.html'), __DIR__); $mail->Body = $this->message; if($mail->send()){ $result['success'] = True; $result['message'] = ['Message has been sent.']; }else{ $result['error'] = True; $result['message'] = ['Message could not be sent.', 'Mailer Error: ' . $mail->ErrorInfo]; } return $result; } }