فهرست منبع

Added logging to help with Unable to Send Test Email (#1221)

CauseFX 6 سال پیش
والد
کامیت
ea596b884e
3فایلهای تغییر یافته به همراه19 افزوده شده و 4 حذف شده
  1. 1 0
      api/plugins/config/php-mailer.php
  2. 3 0
      api/plugins/js/php-mailer.js
  3. 15 4
      api/plugins/php-mailer.php

+ 1 - 0
api/plugins/config/php-mailer.php

@@ -1,6 +1,7 @@
 <?php
 return array(
 	'PHPMAILER-enabled' => false,
+	'PHPMAILER-debugTesting' => false,
 	'PHPMAILER-smtpHost' => '',
 	'PHPMAILER-smtpHostPort' => '',
 	'PHPMAILER-smtpHostAuth' => true,

+ 3 - 0
api/plugins/js/php-mailer.js

@@ -309,6 +309,9 @@ $(document).on('click', '.phpmSendTestEmail', function() {
         var response = JSON.parse(data);
         if(response.data == true){
             messageSingle('',window.lang.translate('Email Test Successful'),activeInfo.settings.notifications.position,'#FFF','success','5000');
+        }else if(response.data.indexOf('|||DEBUG|||') == 0) {
+            messageSingle('',window.lang.translate('Press F11 to check Console for output'),activeInfo.settings.notifications.position,'#FFF','warning','20000');
+            console.warn(response.data);
         }else{
             messageSingle('',response.data,activeInfo.settings.notifications.position,'#FFF','error','5000');
         }

+ 15 - 4
api/plugins/php-mailer.php

@@ -106,7 +106,10 @@ function phpmAdminSendEmail()
 	}
 	return false;
 }
-
+function phpmGetDebug($str, $level){
+	$GLOBALS['phpmOriginalDebug'] = $GLOBALS['phpmOriginalDebug'] . $str;
+	return $GLOBALS['phpmOriginalDebug'];
+}
 function phpmSendTestEmail()
 {
 	$emailTemplate = array(
@@ -118,10 +121,12 @@ function phpmSendTestEmail()
 		'inviteCode' => null,
 	);
 	$emailTemplate = phpmEmailTemplate($emailTemplate);
+	$GLOBALS['phpmOriginalDebug'] = '|||DEBUG|||';
 	try {
 		$mail = new PHPMailer\PHPMailer\PHPMailer(true);
+		$mail->SMTPDebug = 2;
 		$mail->isSMTP();
-		//$mail->SMTPDebug = 3;
+		$mail->Debugoutput = function($str, $level) {phpmGetDebug($str, $level);};
 		$mail->Host = $GLOBALS['PHPMAILER-smtpHost'];
 		$mail->Port = $GLOBALS['PHPMAILER-smtpHostPort'];
 		if ($GLOBALS['PHPMAILER-smtpHostType'] !== 'n/a') {
@@ -147,10 +152,10 @@ function phpmSendTestEmail()
 		$mail->Body = phpmBuildEmail($emailTemplate);
 		$mail->send();
 		writeLog('success', 'Mail Function -  E-Mail Test Sent', $GLOBALS['organizrUser']['username']);
-		return true;
+		return ($GLOBALS['PHPMAILER-debugTesting']) ? $GLOBALS['phpmOriginalDebug'] : true;
 	} catch (PHPMailer\PHPMailer\Exception $e) {
 		writeLog('error', 'Mail Function -  E-Mail Test Failed[' . $mail->ErrorInfo . ']', $GLOBALS['organizrUser']['username']);
-		return $e->errorMessage();
+		return ($GLOBALS['PHPMAILER-debugTesting']) ? $GLOBALS['phpmOriginalDebug'] : $e->errorMessage();
 	}
 	return false;
 }
@@ -302,6 +307,12 @@ function phpmGetSettings()
 				'icon' => 'fa fa-paper-plane',
 				'text' => 'Send'
 			),
+			array(
+				'type' => 'switch',
+				'name' => 'PHPMAILER-debugTesting',
+				'label' => 'Enable Debug Output on Email Test',
+				'value' => $GLOBALS['PHPMAILER-debugTesting'],
+			),
 			array(
 				'type' => 'input',
 				'name' => 'PHPMAILER-domain',