'PHP Mailer', // Plugin Name 'author'=>'PHP Mailer', // Who wrote the plugin 'category'=>'Mail', // One to Two Word Description 'link'=>'https://github.com/PHPMailer/PHPMailer', // Link to plugin info //'fileName'=>'php-mailer.php', //'configFile'=>'php-mailer.php', //'apiFile'=>'php-mailer.php', 'idPrefix'=>'PHPMAILER', // html element id prefix 'configPrefix'=>'PHPMAILER', // config file prefix for array items without the hypen 'version'=>'1.0.0', // SemVer of plugin 'image'=>'plugins/images/php-mailer.png', // 1:1 non transparent image for plugin 'settings'=>true, // does plugin need a settings page? true or false 'homepage'=>false // Is plugin for use on homepage? true or false ); // INCLUDE/REQUIRE FILES // PLUGIN FUNCTIONS function getTemplates(){ foreach (glob(dirname(__DIR__,2).DIRECTORY_SEPARATOR.'api' .DIRECTORY_SEPARATOR.'plugins' .DIRECTORY_SEPARATOR.'misc' . DIRECTORY_SEPARATOR . 'emailTemplates' . DIRECTORY_SEPARATOR . "*.php") as $filename){ $templates[] = array( 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)), 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)) ); } return $templates; } function phpmEmailTemplate($emailTemplate){ $variables = [ '{user}' => $emailTemplate['user'], '{domain}' => getServerPath(true), '{password}' => $emailTemplate['password'], '{inviteCode}' => $emailTemplate['inviteCode'], '{fullDomain}' => getServerPath(true), ]; $emailTemplate['body'] = strtr($emailTemplate['body'], $variables); $emailTemplate['subject'] = strtr($emailTemplate['subject'], $variables); return $emailTemplate; } function phpmBuildEmail($email){ $subject = (isset($email['subject'])) ? $email['subject'] : 'Message from Server'; $body = (isset($email['body'])) ? $email['body'] : 'Message Error Occured'; $type = (isset($email['type'])) ? $email['type'] : 'No Type'; switch ($type) { case 'invite': $extra = 'invite'; break; case 'reset': $extra = 'reset'; break; default: $extra = null; break; } include('misc/emailTemplates/'.$GLOBALS['PHPMAILER-template'].'.php'); return $email; } function phpmSendTestEmail(){ try { $mail = new PHPMailer\PHPMailer\PHPMailer(true); $mail->isSMTP(); //$mail->SMTPDebug = 3; $mail->Host = $GLOBALS['PHPMAILER-smtpHost']; $mail->Port = $GLOBALS['PHPMAILER-smtpHostPort']; $mail->SMTPSecure = $GLOBALS['PHPMAILER-smtpHostType']; $mail->SMTPAuth = $GLOBALS['PHPMAILER-smtpHostAuth']; $mail->Username = $GLOBALS['PHPMAILER-smtpHostUsername']; $mail->Password = decrypt($GLOBALS['PHPMAILER-smtpHostPassword']); $mail->setFrom($GLOBALS['PHPMAILER-smtpHostSenderEmail'], $GLOBALS['PHPMAILER-smtpHostSenderName']); $mail->addReplyTo($GLOBALS['PHPMAILER-smtpHostSenderEmail'], $GLOBALS['PHPMAILER-smtpHostSenderName']); $mail->isHTML(true); $mail->addAddress($GLOBALS['organizrUser']['email'], $GLOBALS['organizrUser']['username']); $mail->Subject = "Organizr Test E-Mail"; $mail->Body = "This was just a test!"; $mail->send(); writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']); return true; } catch (PHPMailer\PHPMailer\Exception $e) { writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']); return $e->errorMessage(); } return false; } function phpmSendEmail($emailInfo){ $to = isset($emailInfo['to']) ? $emailInfo['to'] : null; $cc = isset($emailInfo['cc']) ? $emailInfo['cc'] : null; $bcc = isset($emailInfo['bcc']) ? $emailInfo['bcc'] : null; $subject = isset($emailInfo['subject']) ? $emailInfo['subject'] : null; $body = isset($emailInfo['body']) ? $emailInfo['body'] : null; $username = isset($emailInfo['user']) ? $emailInfo['user'] : 'Organizr User'; try { $mail = new PHPMailer\PHPMailer\PHPMailer(true); $mail->isSMTP(); //$mail->SMTPDebug = 3; $mail->Host = $GLOBALS['PHPMAILER-smtpHost']; $mail->Port = $GLOBALS['PHPMAILER-smtpHostPort']; $mail->SMTPSecure = $GLOBALS['PHPMAILER-smtpHostType']; $mail->SMTPAuth = $GLOBALS['PHPMAILER-smtpHostAuth']; $mail->Username = $GLOBALS['PHPMAILER-smtpHostUsername']; $mail->Password = decrypt($GLOBALS['PHPMAILER-smtpHostPassword']); $mail->setFrom($GLOBALS['PHPMAILER-smtpHostSenderEmail'], $GLOBALS['PHPMAILER-smtpHostSenderName']); $mail->addReplyTo($GLOBALS['PHPMAILER-smtpHostSenderEmail'], $GLOBALS['PHPMAILER-smtpHostSenderName']); $mail->isHTML(true); if($to){ $mail->addAddress($to, $username); } if($cc){ $mail->addCC($cc); } if($bcc){ if(strpos($bcc , ',') === false){ $mail->addBCC($bcc); }else{ $allEmails = explode(",",$bcc); foreach($allEmails as $gotEmail){ $mail->addBCC($gotEmail); } } } $mail->Subject = $subject; $mail->Body = $body; $mail->send(); //writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']); return true; } catch (PHPMailer\PHPMailer\Exception $e) { writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']); return $e->errorMessage(); } return false; } /* GET PHPMAILER SETTINGS */ function phpmGetSettings(){ return array( 'Host' => array( array( 'type' => 'input', 'name' => 'PHPMAILER-smtpHost', 'label' => 'SMTP Host', 'value' => $GLOBALS['PHPMAILER-smtpHost'] ), array( 'type' => 'input', 'name' => 'PHPMAILER-smtpHostPort', 'label' => 'SMTP Port', 'value' => $GLOBALS['PHPMAILER-smtpHostPort'] ) ), 'Authentication' => array( array( 'type' => 'input', 'name' => 'PHPMAILER-smtpHostUsername', 'label' => 'Username', 'value' => $GLOBALS['PHPMAILER-smtpHostUsername'] ), array( 'type' => 'password', 'name' => 'PHPMAILER-smtpHostPassword', 'label' => 'Password', 'value' => $GLOBALS['PHPMAILER-smtpHostPassword'] ), array( 'type' => 'switch', 'name' => 'PHPMAILER-smtpHostAuth', 'label' => 'Authentication', 'value' => $GLOBALS['PHPMAILER-smtpHostAuth'] ), array( 'type' => 'select', 'name' => 'PHPMAILER-smtpHostType', 'label' => 'Authentication Type', 'value' => $GLOBALS['PHPMAILER-smtpHostType'], 'options' => array( array( 'name'=>'tls', 'value'=>'tls' ), array( 'name'=>'ssl', 'value'=>'ssl' ), array( 'name'=>'off', 'value'=>'false' ) ) ) ), 'Sender Information' => array( array( 'type' => 'input', 'name' => 'PHPMAILER-smtpHostSenderName', 'label' => 'Sender Name', 'value' => $GLOBALS['PHPMAILER-smtpHostSenderName'] ), array( 'type' => 'input', 'name' => 'PHPMAILER-smtpHostSenderEmail', 'label' => 'Sender Email', 'value' => $GLOBALS['PHPMAILER-smtpHostSenderEmail'], 'placeholder' => 'i.e. same as username' ) ), 'Test & Options' => array( array( 'type' => 'button', 'label' => 'Send Test', 'class' => 'phpmSendTestEmail', 'icon' => 'fa fa-paper-plane', 'text' => 'Send' ), array( 'type' => 'input', 'name' => 'PHPMAILER-domain', 'label' => 'Domain Link Override', 'value' => $GLOBALS['PHPMAILER-domain'], 'placeholder' => 'https://domain.com/', ), array( 'type' => 'select', 'name' => 'theme', 'label' => 'Theme', 'class' => 'themeChanger', 'value' => $GLOBALS['PHPMAILER-template'], 'options' => getTemplates() ), array( 'type' => 'input', 'name' => 'PHPMAILER-logo', 'label' => 'WAN Logo URL', 'value' => $GLOBALS['PHPMAILER-logo'], 'placeholder' => 'Full URL', ), ), 'Templates' => array( array( 'type' => 'accordion', 'label' => 'Edit Template', 'id' => 'customEmailTemplates', 'override' => 12, 'options' => array( array( 'id' => 'PHPMAILER-emailTemplateRegisterUserForm', 'header' => 'New Registration', 'body' => array( array( 'type' => 'input', 'name' => 'PHPMAILER-emailTemplateRegisterUserSubject', 'smallLabel' => 'Subject', 'value' => $GLOBALS['PHPMAILER-emailTemplateRegisterUserSubject'], ), array( 'type' => 'textbox', 'name' => 'PHPMAILER-emailTemplateRegisterUser', 'smallLabel' => 'Body', 'value' => $GLOBALS['PHPMAILER-emailTemplateRegisterUser'], 'attr' => 'rows="10"', ) ) ), array( 'id' => 'PHPMAILER-emailTemplateResetPasswordForm', 'header' => 'Reset Password', 'body' => array( array( 'type' => 'input', 'name' => 'PHPMAILER-emailTemplateResetPasswordSubject', 'smallLabel' => 'Subject', 'value' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'], ), array( 'type' => 'textbox', 'name' => 'PHPMAILER-emailTemplateResetPassword', 'smallLabel' => 'Body', 'value' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'], 'attr' => 'rows="10"', ) ) ), array( 'id' => 'PHPMAILER-emailTemplateInviteUserForm', 'header' => 'Invite User', 'body' => array( array( 'type' => 'input', 'name' => 'PHPMAILER-emailTemplateInviteUserSubject', 'smallLabel' => 'Subject', 'value' => $GLOBALS['PHPMAILER-emailTemplateInviteUserSubject'], ), array( 'type' => 'textbox', 'name' => 'PHPMAILER-emailTemplateInviteUser', 'smallLabel' => 'Body', 'value' => $GLOBALS['PHPMAILER-emailTemplateInviteUser'], 'attr' => 'rows="10"', ) ) ), ) ) ) ); }