<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: contactmailer.php,v 1.9.2.2 2004/04/18 12:45:41 ajvwaay Exp $



################################################################################
# Filename: contactmailer.php
# Author: John Hoke
# Purpose: Cheap and dirty User Comment emailer. Receives form info, sends mail
#          to site admin, and a confirmation message is mailed to the user, as
#          well as a webpage confirmation in the browser.
# email: admin@slapd.net
# version: 0.5 beta
#
#       Do what you want with this script, just do not remove the text above
#
################################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
# USA.
#
################################################################################

/*2001-03-29 jeffx      - Reworked this file entirely. Better syntax and tables
                          is opened with the right functions.
                        - Fixed the quotes being slashed when email sent
                        - Non-mandatory variables are not included in the email
                          if the user hasn't specified them.*/


//include("extention.inc");
//if (!isset($mainfile)) { include("mainfile.php"); }
include("header.php");
require_once('class.phpmailer.php');
$mail = new phpmailer();

/* SET MAIL DELIVERY OPTIONS*/
$mail->IsHTML(true);
if ($mailmethod == "0") {
    $mail->IsMail();
} else {
    $mail->IsSMTP();
    $mail->Host = $smtp;
}

/*$usersEmail = stripslashes(check_html($usersEmail, "nohtml"));
$usersCompanyName = stripslashes(check_html($usersCompanyName, "nohtml"));
$usersCompanyLocation = stripslashes(check_html($usersCompanyLocation, "nohtml"));
$usersSubject = stripslashes(check_html($usersSubject, "nohtml"));
$usersComments = stripslashes(check_html($usersComments, "nohtml"));
$usersName = stripslashes(check_html($usersName, "nohtml"));*/

// Validate Info


// Check For Empty

$check_ary = array( $_POST['usersName'], $_POST['usersEmail'], $_POST['usersSubject'], $_POST['usersComments'] );

$verify_check_ary = $_SERVER['SAN'] -> verifyContent( $check_ary, 3 );

if ( in_array( (bool)FALSE, $verify_check_ary ) )
{
    goBack( translate( 'You Failed To Include Required Information' ) );
    exit;
}

// Check URL

if ( isset( $_POST['usersSite'] ) && $_POST['usersSite'] != '' && ! $_SERVER['SAN'] -> verifyContent( $_POST['usersSite'], 1 ) )
{
    goBack( translate( 'Invalid URL' ) );
    exit;
}

// Check Email

if ( ! $_SERVER['SAN'] -> verifyContent( $_POST['usersEmail'], 2 ) )
{
    goBack( translate( 'Invalid Email' ) );
    exit;
}

unset( $check_ary, $verify_check_ary );


$UserMessage = sprintf(translate("%s, Thank you for your comments about %s."),$usersName,$sitename);
$UserMessage .= "\n";
$UserMessage .= sprintf(translate("Your message has been sent to the webmaster(s) of %s"),$sitename);
$UserMessage .= "\n";
$UserMessage .= "$mpn_webmaster_name\n";
$UserMessage .= $sitename . ' ' . translate('Administration')."\n";
$UserMessage .= "$adminmail";

$AdminMessage = sprintf(translate("%s, Submitted the following Information:"),$usersName);
$AdminMessage .= "\n";
$AdminMessage .= "Email: $usersEmail\n";
if ($usersSite != "")
    $AdminMessage .= "URL: $usersSite\n";
if ($usersICQ != "")
    $AdminMessage .= "ICQ: $usersICQ\n";
if ($usersCompanyName != "")
    $AdminMessage .= translate("Company:"). " $usersCompanyName\n";
if ($usersCompanyLocation != "")
    $AdminMessage .= translate("Location:")." $usersCompanyLocation\n";
$AdminMessage .= translate("Subject:")."\n";
$AdminMessage .= "$usersSubject\n";
$AdminMessage .= translate("Comments:")."\n";
$AdminMessage .= "$usersComments\n";
$AdminMessage .= "\n$HTTP_USER_AGENT\n";
$subject = $sitename." - ".translate("Contact Us Form");
//mail("$usersEmail", "$mpn_conf_subject", $UserMessage, "From: $adminmail");
//mail("$adminmail", "$subject", $AdminMessage, "From: $usersEmail");
/* SEND ADMIN MESSAGE */
$mail->From = $usersEmail;
$mail->FromName = $sitename . translate(' Mailer');
$mail->AddAddress($adminmail);
$mail->Subject = stripslashes($subject);
$mail->Body = stripslashes(nl2br($AdminMessage));
$mail->AltBody = strip_tags( stripslashes($AdminMessage) );
if(!$mail->Send()) {
    OpenTable();
    echo '<div align = "center">' . translate("Sorry, mail wasn't sent");
    echo '<br>';
//    echo translate('Opps, ') . $mail->ErrorInfo;
    echo translate('Please try again later.') . '<br>';
    echo '<a href = "./">' . translate('Index Page') . '</a>';
    echo '<br></div>';
    CloseTable();
    include('footer.php');
    exit;
}

/* CLEAR TO: ADDRESS FROM PREVIOUS SENT EMAIL */
$mail->ClearAddresses();

/* SEND USER MESSAGE */
$mail->From = $adminmail;
$mail->FromName = $sitename . translate(' Mailer');
$mail->AddAddress($usersEmail);
$mail->Subject = stripslashes($mpn_conf_subject);
$mail->Body = stripslashes(nl2br($UserMessage));
$mail->AltBody = strip_tags( stripslashes($UserMessage) );
if(!$mail->Send()) {
    OpenTable();
    echo '<div align = "center">' . translate("Sorry, mail wasn't sent");
    echo '<br>';
    //    echo translate('Opps, ') . $mail->ErrorInfo;
    echo translate('Please try again later.') . '<br>';
    echo '<a href = "./">' . translate('Index Page') . '</a>';
    echo '<br></div>';
    CloseTable();
    include('footer.php');
    exit;
}

/* DISPLAY IF MAIL WAS SENT SUCCESSFULLY */
OpenTable();
    echo "<center><h3>";
    echo sprintf(translate("Message to %s Sent:"),$sitename);
    echo "</h3>";
    echo translate("Hello").", $usersName";
    echo ".<br /><br />";
    echo translate("Thank you for your interest in our site!");
    echo "<br /><br />";
    echo sprintf(translate("Your comments have been sent to: %s as a confirmation email."),$usersEmail);
    echo "</center>";
CloseTable();

include("footer.php");

?>
