Mod Title: SMTP Configuration v1.0

Mod Author: Scan & John Briggs

Mod Description:
This mod offers the ability to connect to the SMTP Server and authenticate user to send email out.

Supported Version: XMB 1.9.5 Nexus Final

Installation Note: Before adding this mod to your forum, you should back up all files related to this mod.

License Note: This mod is released under the GPL License.

Author Note:
For security purposes, Please Check: http://www.xmbmods.com for the latest version of this mod.
Downloading this mod from other sites could cause malicious code to enter into your XMB Forum software.
As such, xmbmods.com will not offer support for mod's not offered in our mod forum.
Before adding this mod to your forum, You should back up all files related to this mod.

=======================================================================================================================================
=======
Step 1:
=======

===================================
Go To Admin Panel -> Insert Raw SQL
===================================

Upload provided file named "SQL.txt" & click "Submit Changes" button.

=======================================================================================================================================
=======
Step 2:
=======

================================
Edit File: lang/English.lang.php
================================

===============
Add To End Of File:
===============

// SMTP Configuration Mod Begin
$lang['Smtp_Failed'] = "Failed to connect to out going mail server!";
$lang['Smtp_Settings'] = "SMTP Settings";
$lang['Smtp_Status'] = "SMTP Server Status:";
$lang['Smtp_Server'] = "SMTP Server Address:<br /><small>The Internet address of the mail server that $bbname should connect to when sending your messages.</small>";
$lang['Smtp_Port_Number'] = "SMTP Server Port Number:<br /><small>By default, this setting uses port 25 that is the Internet standard for receiving SMTP mail.</small>";
$lang['Smtp_Timeout'] = "SMTP Server Timeout:<br /><small>This should be set no lower than 30 for best results.</small>";
$lang['Smtp_Username'] = "SMTP Username:<br /><small>Only enter a username if your SMTP server requires it.</small>";
$lang['Smtp_Password'] = "SMTP Password:<br /><small>Only enter a password if your SMTP server requires it.</small>";
$lang['Smtp_Host'] = "SMTP Server Host:<br /><small>This is set to <u>localhost</u> by default.</small>";
// SMTP Configuration Mod End

=======================================================================================================================================
=======
Step 3:
=======

=====================================
Edit File: include/admin.user.inc.php
=====================================

==========
Find Code:
==========

    &raquo;&nbsp;<a href="cp.php?action=settings"><?php echo $lang['textsettings']?></a><br />

===============
Add Code Below:
===============

    &raquo;&nbsp;<a href="cp_smtp.php"><?php echo $lang['Smtp_Settings']?></a><br />

=======================================================================================================================================
=======
Step 4:
=======

==============================
Edit File: include/u2u.inc.php
==============================

==========
Find Code:
==========

global $db, $self, $table_u2u, $timeoffset, $lang, $u2uheader, $u2ufooter;

==================
Replace Code With:
==================

global $db, $self, $table_u2u, $timeoffset, $lang, $u2uheader, $u2ufooter, $SETTINGS;

==========
Find Code:
==========

                        altMail( $rcpt['email'], "$lang[textnewu2uemail]", "$self[username] $lang[textnewu2ubody] \n$u2uurl", "From: $bbname <$adminemail>" );

==================
Replace Code With:
==================

                        if ($SETTINGS['smtp_status'] == 'on') {
                            authemail($rcpt['email'], $username, "$lang[textnewu2uemail]", "$self[username] $lang[textnewu2ubody] \n$u2uurl", $adminemail, $bbname);
                        } else {
                            AltMail($rcpt['email'], "$lang[textnewu2uemail]", "$self[username] $lang[textnewu2ubody] \n$u2uurl", "From: $bbname <$adminemail>");
                        }

==========
Find Code:
==========

                    altMail( $rcpt['email'], "$lang[textnewu2uemail]", "$self[username] $lang[textnewu2ubody] \n$u2uurl", "From: $bbname <$adminemail>" );

==================
Replace Code With:
==================

                    if ($SETTINGS['smtp_status'] == 'on') {
                        authemail($rcpt['email'], $username, "$lang[textnewu2uemail]", "$self[username] $lang[textnewu2ubody] \n$u2uurl", $adminemail, $bbname);
                    } else {
                        altMail($rcpt['email'], "$lang[textnewu2uemail]", "$self[username] $lang[textnewu2ubody] \n$u2uurl", "From: $bbname <$adminemail>");
                    }

==========
Find Code:
==========

            altMail($self['email'], $lang['textu2utoemail'] . " " . $u2usubject, $email, 'From: '.$bbname.' <'.$self['email'].">\r\n".'Content-type: text/html');

==================
Replace Code With:
==================

            if ($SETTINGS['smtp_status'] == 'on') {
                authemail($self['email'], $self['username'], $lang['textu2utoemail']." ".$u2usubject, $email, $adminemail, $bbname);
            } else {
                altMail($self['email'], $lang['textu2utoemail']." ".$u2usubject, $email, "From: $bbname \r\nContent-type: text/html");
            }

=======================================================================================================================================
=======
Step 5:
=======

==================
Edit File: cp2.php
==================

==========
Find Code:
==========

                altMail($memnews['email'], '['.$bbname.'] '.$newssubject, $newsmessage, $headers);

==================
Replace Code With:
==================

                if ($SETTINGS['smtp_status'] == 'on') {
                    authemail($memnews['email'], $memnews['username'], '['.$bbname.'] '.$newssubject, $newsmessage, $adminemail, $bbname);
                } else {
                    altMail($memnews['email'], '['.$bbname.'] '.$newssubject, $newsmessage, $headers);
                }

=======================================================================================================================================
=======
Step 6:
=======

========================
Edit File: functions.php
========================

=========================
Find Code At Very Bottom:
=========================

?>

===============
Add Code Above:
===============

/**
* authemail() - send an email using auth smtp
*
* Connects to the SMTP Server and authenticates user to send email out
*
* @param string $to users email address
* @param string $userto users site name
* @param string $subject subject of the email
* @param string $body main message
* @param string $from can be the current users email or the board administrators email
* @param string $userfrom can be the current user or the board admin
*
* @return void, returns nothing
*/
function authemail($to, $userto, $subject, $body, $from, $userfrom) {
    global $SETTINGS, $lang;

    // Connect to the host on the specified port
    $smtpConnect = fsockopen($SETTINGS['smtpServer'], $SETTINGS['smtpport'], $errno, $errstr, $SETTINGS['smtptimeout']);
    // Show error if connection fails
    if (empty($smtpConnect)) {
        error($lang['Smtp_Failed']);
    }
    // Auth Login
    fputs($smtpConnect,"AUTH LOGIN \r\n");
    // Username
    fputs($smtpConnect, base64_encode($SETTINGS['smtpusername']) . "\r\n");
    // Password
    fputs($smtpConnect, base64_encode($SETTINGS['smtppassword']) . "\r\n");
    // Helo
    fputs($smtpConnect, "HELO ".$SETTINGS['smtphost']." \r\n");
    // Email From
    fputs($smtpConnect, "MAIL FROM: $from \r\n");
    // Email To
    fputs($smtpConnect, "RCPT TO: $to \r\n");
    // Bring The Email Together
    fputs($smtpConnect, "DATA \r\n");
    // Construct Headers
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "To: $userto <$to>";
    $headers[] = "From: $userfrom <$from>";
    $headers = implode("\r\n", $headers);
    fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$body\n.\n");
    // QUIT
    fputs($smtpConnect,"QUIT \r\n");
}

=======================================================================================================================================
=======
Step 7:
=======

=====================
Edit File: member.php
=====================

==========
Find Code:
==========

                    altMail($notify['email'], $lang['textnewmember'], $lang['textnewmember2'], $headers);

==================
Replace Code With:
==================

                    if ($SETTINGS['smtp_status'] == 'on') {
                        authemail($notify['email'], $notify['username'], $lang['textnewmember'], $lang['textnewmember2'], $adminemail, $bbname);
                    } else {
                        altMail($notify['email'], $lang['textnewmember'], $lang['textnewmember2'], $headers);
                    }

==========
Find Code:
==========

            altMail($email, $lang['textyourpw'], $lang['textyourpwis']." \n\n$username\n$password2", "From: $bbname <$adminemail>");

==================
Replace Code With:
==================

            if ($SETTINGS['smtp_status'] == 'on') {
                authemail($email, $username, '['.$bbname.'] '.$lang['textyourpw'], $lang['textyourpwis']." \n\n$username\n$password2", $adminemail, $bbname);
            } else {
                altMail($email, $lang['textyourpw'], $lang['textyourpwis']." \n\n$username\n$password2", "From: $bbname <$adminemail>");
            }

=======================================================================================================================================
=======
Step 8:
=======

===================
Edit File: misc.php
===================

==========
Find Code:
==========

false !== strpos($url, "/cp.php") || false !== strpos($url, "/cp2.php")

==================
Replace Code With:
==================

false !== strpos($url, "/cp.php") || false !== strpos($url, "/cp2.php") || false !== strpos($url, "/cp_smtp.php")

==========
Find Code:
==========

                altMail($member['email'], '['.$bbname.'] '.$lang['textyourpw'], $lang['textyourpwis']."\n\n".$member['username']."\n".$newpass, "From: ".$bbname." <".$adminemail.">");

==================
Replace Code With:
==================

                if ($SETTINGS['smtp_status'] == 'on') {
                    authemail($member['email'], $member['username'], '['.$bbname.'] '.$lang['textyourpw'], $lang['textyourpwis']."\n\n".$member['username']."\n".$newpass, $adminemail, $bbname);
                } else {
                    altMail($member['email'], '['.$bbname.'] '.$lang['textyourpw'], $lang['textyourpwis']."\n\n".$member['username']."\n".$newpass, "From: ".$bbname." <".$adminemail.">");
                }

=======================================================================================================================================
=======
Step 9:
=======

===================
Edit File: post.php
===================

==========
Find Code:
==========

            $subquery = $db->query("SELECT m.email, m.lastvisit, m.ppp, m.status FROM $table_favorites f LEFT JOIN $table_members m ON (m.username=f.username) WHERE f.type='subscription' AND f.tid='$tid' AND f.username != '$username'");

==================
Replace Code With:
==================

            $subquery = $db->query("SELECT m.username, m.email, m.lastvisit, m.ppp, m.status FROM $table_favorites f LEFT JOIN $table_members m ON (m.username=f.username) WHERE f.type='subscription' AND f.tid='$tid' AND f.username != '$username'");

==========
Find Code:
==========

                altMail($subs['email'], $lang['textsubsubject'].' '.$threadname, $username.' '.$lang['textsubbody']." \n".$threadurl, "From: $bbname <$adminemail>");

==================
Replace Code With:
==================

                if ($SETTINGS['smtp_status'] == 'on') {
                    authemail($subs['email'], $subs['username'], $lang['textsubsubject'].' '.$threadname, $username.' '.$lang['textsubbody']." \n".$threadurl, $adminemail, $bbname);
                } else {
                    altMail($subs['email'], $lang['textsubsubject'].' '.$threadname, $username.' '.$lang['textsubbody']." \n".$threadurl, "From: $bbname <$adminemail>");
                }

=======================================================================================================================================
========
Step 10:
========

Upload provided file named "cp_smtp.php" to your forum root directory.

=======================================================================================================================================