Browse Source

dev 2019-11

Max YO 6 years ago
parent
commit
1b32c26938
2 changed files with 43 additions and 6 deletions
  1. 37 0
      helpers/helpers_smtp_hooks.php
  2. 6 6
      src/Lib/Email/Email_lib.php

+ 37 - 0
helpers/helpers_smtp_hooks.php

@@ -0,0 +1,37 @@
+<?php
+
+use \KarmaFW\Lib\Email_lib;
+
+
+function smtp_hook_email($to, $subject, $message_html, $message_text='', $from=null, $from_name=null, $options=[]) {
+	// redirige les emails vers vers SMTP_HOOK_EMAIL
+	if (! defined('SMTP_HOOK_EMAIL')) {
+		return false;
+	}
+	$to = SMTP_HOOK_EMAIL;
+	$options['no_hook'] = true;
+	return \KarmaFW\Lib\Email_lib::sendmailSMTP($to, $subject, $message_html, $message_text, $from, $from_name, $options);
+}
+
+function smtp_hook_domain($to, $subject, $message_html, $message_text='', $from=null, $from_name=null, $options=[]) {
+	// redirige les emails vers vers SMTP_HOOK_DOMAIN  -  exemple:  paul.martin@gmail.com => paul.martin__gmail.com@mon-domaine-a-moi.com
+	if (! defined('SMTP_HOOK_DOMAIN')) {
+		return false;
+	}
+	$to = str_replace("@", "__", $to) . "@" . SMTP_HOOK_DOMAIN;
+	$options['no_hook'] = true;
+	return \KarmaFW\Lib\Email_lib::sendmailSMTP($to, $subject, $message_html, $message_text, $from, $from_name, $options);
+}
+
+
+function smtp_hook_false($to, $subject, $message_html, $message_text='', $from=null, $from_name=null, $options=[]) {
+	// n'envoie aucun email et retourne FALSE
+	return false;
+}
+
+function smtp_hook_true($to, $subject, $message_html, $message_text='', $from=null, $from_name=null, $options=[]) {
+	// n'envoie aucun email et retourne TRUE
+	return false;
+}
+
+

+ 6 - 6
src/Lib/Email/Email_lib.php

@@ -18,13 +18,13 @@ class Email_lib
 
 	public static function sendmailSMTP($to, $subject, $message_html, $message_text='', $from=null, $from_name=null, $options=[]) {
 
-		if (defined('SMTP_CALLBACK') && empty($options['no_callback'])) {
-			$smtp_callback_func = SMTP_CALLBACK;
-			if (is_callable($smtp_callback_func)) {
-				return $smtp_callback_func($to, $subject, $message_html, $message_text, $from, $from_name);
+		if (defined('SMTP_HOOK') && empty($options['no_hook'])) {
+			$smtp_hook_func = SMTP_HOOK;
+			if (is_callable($smtp_hook_func)) {
+				return $smtp_hook_func($to, $subject, $message_html, $message_text, $from, $from_name);
 			}
-			// aucun message envoyé ni callback
-			return boolval($smtp_callback_func); // permet de mettre "1" pour un retour ok ou "0" pour un retour en erreur
+			// aucun message envoyé ni hook
+			return boolval($smtp_hook_func); // permet de mettre "1" pour un retour ok ou "0" pour un retour en erreur
 		}
 
 		if (true) {