Permalink
Browse files

SG

  • Loading branch information...
root
root committed Oct 17, 2018
1 parent b509e6c commit d0de97b1dfff818ecb2e94a107fa493cc0d4dc97
Showing with 5,408 additions and 0 deletions.
  1. +182 −0 nuemailer.php
  2. +4,040 −0 phpmailer/nuemailer/class-phpmailer.php
  3. +1,186 −0 phpmailer/nuemailer/class-smtp.php
@@ -0,0 +1,182 @@
<?php
function nuEmail($to_list=array(),$from_address='',$from_name='',$content='',$subject='',$file_list=array(),$html=false,$carbon_copy_list=array(),$blind_carbon_copy_list=array(),$reply_to_list=array(),$debug=0,$method='SMTP') {
ob_start();
$nuEmailSettings = nuMarshallEmailSettings($from_address, $from_name, $html, $reply_to_list);
require_once($nuEmailSettings->phpmailer_path);
$mail = new PHPMailer();
$mail->SMTPDebug = $debug;
if ( $method == 'SMTP' ) {
$mail->isSMTP();
}
if ( $method == 'sendmail' ) {
$mail->isSendmail();
}
$mail->Subject = $subject;
$mail->Body = $content;
$mail->Username = $nuEmailSettings->username; // defaults to ''
$mail->Password = $nuEmailSettings->password; // defaults to ''
$mail->Host = $nuEmailSettings->host; // defaults to 127.0.0.1
$mail->From = $nuEmailSettings->from_address; // defaults to ''
$mail->FromName = $nuEmailSettings->from_name; // defaults to ''
$mail->Port = $nuEmailSettings->smtp_port; // defaults to 25
$mail->SMTPSecure = $nuEmailSettings->smtp_secure; // defaults to '' otherwsie it will be tls or ssl
$mail->SMTPAuth = $nuEmailSettings->smtp_use_authentication; // defaults to false
$mail->WordWrap = $nuEmailSettings->word_wrap; // defaults to 120
$mail->CharSet = $nuEmailSettings->charset; // defaults to UTF-8
$mail->IsHTML($nuEmailSettings->html);
_nuEmailHelperAdd($mail, $to_list, 'AddAddress');
_nuEmailHelperAdd($mail, $nuEmailSettings->reply_to_list, 'AddReplyTo');
_nuEmailHelperAdd($mail, $carbon_copy_list, 'AddCC');
_nuEmailHelperAdd($mail, $blind_carbon_copy_list, 'AddBCC');
_nuEmailHelperAttach($mail, $file_list);
$mail->Send();
_nuEmailHelperClean($file_list);
$result = array();
$result[0] = "\n".ob_get_contents();
$result[1] = $mail->ErrorInfo;
ob_end_clean();
return $result;
}
function _nuMarshallEmailSettingsHelper($obj, $key, $default = '') {
if ( !is_object($obj) ) {
return $default;
}
if ( !isset($obj->$key) ) {
return $default;
}
if ( empty(trim($obj->$key)) ) {
return $default;
}
return trim($obj->$key);
}
function nuMarshallEmailSettings( $from_address = '', $from_name = '', $html = false, $reply_to_list = array() ) {
$word_press_path = '../../../wp-includes/class-phpmailer.php';
$standalone_path = 'phpmailer/nuemailer/class-phpmailer.php';
$setup = db_setup();
$nuEmailSettings = new stdClass();
$nuEmailSettings->error_text = '';
$nuEmailSettings->username = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_username');
$nuEmailSettings->password = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_password');
$nuEmailSettings->host = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_host', '127.0.0.1');
$nuEmailSettings->from_address = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_from_address', $from_address);
$nuEmailSettings->from_name = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_from_name', $from_name);
$nuEmailSettings->smtp_port = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_port', '25');
$nuEmailSettings->smtp_use_secure = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_use_ssl', false);
$nuEmailSettings->smtp_use_authentication = _nuMarshallEmailSettingsHelper($setup, 'set_smtp_use_authentication', false);
$nuEmailSettings->word_wrap = 120;
$nuEmailSettings->charset = 'UTF-8';
$nuEmailSettings->html = $html;
$nuEmailSettings->phpmailer_path = $standalone_path;
$nuEmailSettings->reply_to_list = array();
$nuEmailSettings->smtp_secure = '';
if ( $nuEmailSettings->smtp_port == '587' ) {
$nuEmailSettings->smtp_secure = 'tls';
$nuEmailSettings->verbose_host = 'tls://'.$nuEmailSettings->host.':587';
}
if ( $nuEmailSettings->smtp_port == '465' ) {
$nuEmailSettings->smtp_secure = 'ssl';
$nuEmailSettings->verbose_host = 'ssl://'.$nuEmailSettings->host.':465';
}
if ( empty($reply_to_list) ) {
if ( $from_address != '' ) {
$nuEmailSettings->reply_to_list = array($from_address => $from_name);
}
}
if ( isset($_SESSION) ) {
if ( $_SESSION['nuconfig']->PLUGIN ) {
if ( file_exists($word_press_path) ) {
$nuEmailSettings->phpmailer_path = $word_press_path;
} else {
$nuEmailSettings->error_text .= 'Cannot locate phpmailer files';
}
}
}
return $nuEmailSettings;
}
function _nuEmailHelperAdd(&$mail, $names_addresses, $method) {
if (_is_my_array_associative($names_addresses)) {
_nuEmailHelperAddAssociative($mail, $names_addresses, $method);
} else {
_nuEmailHelperAddOrdinal($mail, $names_addresses, $method);
}
}
function _nuEmailHelperAddOrdinal(&$mail, $names_addresses, $method) {
for ( $x=0; $x<count($names_addresses); $x++ ) {
$mail->$method($names_addresses[$x], '');
}
}
function _nuEmailHelperAddAssociative(&$mail, $names_addresses, $method) {
foreach ( $names_addresses as $key => $value ) {
$mail->$method($key, $value);
}
}
function _nuEmailHelperAttach(&$mail, $file_list = array() ) {
if ( !is_array($file_list) ) {
return;
}
if ( !_is_my_array_associative($file_list) ) {
return;
}
foreach($file_list as $filename=>$filesource) {
$mail->AddAttachment($filesource,$filename);
}
}
function _nuEmailHelperClean($file_list = array() ) {
if ( !is_array($file_list) ) {
return;
}
if ( !_is_my_array_associative($file_list) ) {
return;
}
foreach($file_list as $filename=>$filesource) {
@unlink($filesource);
}
}
function _is_my_array_associative($arr) {
return array_key_exists('0',$arr) ? false : true;
}
?>
Oops, something went wrong.

0 comments on commit d0de97b

Please sign in to comment.