Project

General

Profile

1
<?php
2

    
3
// $Id: class.WbMailer.php 2059 2014-01-01 02:25:04Z darkviper $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25
/* -------------------------------------------------------- */
26
// Must include code to stop this file being accessed directly
27
if(!defined('WB_PATH')) {
28
	require_once(dirname(__FILE__).'/globalExceptionHandler.php');
29
	throw new IllegalFileException();
30
}
31
/* -------------------------------------------------------- */
32
// Include PHPMailer class if needed
33
if (!function_exists('PHPMailerAutoload')) {
34
    require(WbAdaptor::getInstance()->AppPath.'include/phpmailer/PHPMailerAutoload.php');
35
}
36

    
37
class WbMailer extends PHPMailer
38
{
39
	// new websitebaker mailer class (subset of PHPMailer class)
40
	// setting default values 
41

    
42
	function __construct() {
43

    
44
        $oDb = WbDatabase::getInstance();
45
		// set mailer defaults (PHP mail function)
46
		$db_wbmailer_routine = "phpmail";
47
		$db_wbmailer_smtp_host = "";
48
		$db_wbmailer_default_sendername = "WB Mailer";
49
		$db_server_email = SERVER_EMAIL;
50

    
51
		// get mailer settings from database
52
		// $database = new database();
53
		$query = 'SELECT * FROM `'.$oDb->TablePrefix.'settings`';
54
		$oSettingSet = $oDb->doQuery($query);
55
		while($aSettings = $oSettingSet->fetchRow(MYSQL_ASSOC)) {
56
            switch ($aSettings['name']):
57
                case 'wbmailer_routine':
58
                    $db_wbmailer_routine = $aSettings['value']; break;
59
                case 'wbmailer_smtp_host':
60
                    $db_wbmailer_smtp_host = $aSettings['value']; break;
61
                case 'wbmailer_smtp_auth':
62
                    $db_wbmailer_smtp_auth = (bool)$aSettings['value']; break;
63
                case 'wbmailer_smtp_username':
64
                    $db_wbmailer_smtp_username = $aSettings['value']; break;
65
                case 'wbmailer_smtp_password':
66
                    $db_wbmailer_smtp_password = $aSettings['value']; break;
67
                case 'wbmailer_default_sendername':
68
                    $db_wbmailer_default_sendername = $aSettings['value']; break;
69
                case 'server_email':
70
                    $db_server_email = $aSettings['value']; break;
71
                default:
72
                    break;
73
            endswitch;
74
		}
75

    
76
		// set method to send out emails
77
		if($db_wbmailer_routine == "smtp" AND strlen($db_wbmailer_smtp_host) > 5) {
78
			// use SMTP for all outgoing mails send by Website Baker
79
			$this->IsSMTP();                                            
80
			$this->Host = $db_wbmailer_smtp_host;
81
			// check if SMTP authentification is required
82
			if ($db_wbmailer_smtp_auth == "true" && strlen($db_wbmailer_smtp_username) > 1 && strlen($db_wbmailer_smtp_password) > 1) {
83
				// use SMTP authentification
84
				$this->SMTPAuth = true;     	  								// enable SMTP authentification
85
				$this->Username = $db_wbmailer_smtp_username;  	// set SMTP username
86
				$this->Password = $db_wbmailer_smtp_password;	  // set SMTP password
87
			}
88
		} else {
89
			// use PHP mail() function for outgoing mails send by Website Baker
90
			$this->IsMail();
91
		}
92

    
93
		// set language file for PHPMailer error messages
94
		if(defined("LANGUAGE")) {
95
			$this->SetLanguage(strtolower(LANGUAGE),"language");    // english default (also used if file is missing)
96
		}
97

    
98
		// set default charset
99
		if(defined('DEFAULT_CHARSET')) { 
100
			$this->CharSet = DEFAULT_CHARSET; 
101
		} else {
102
			$this->CharSet='utf-8';
103
		}
104

    
105
		// set default sender name
106
		if($this->FromName == 'Root User') {
107
			if(isset($_SESSION['DISPLAY_NAME'])) {
108
				$this->FromName = $_SESSION['DISPLAY_NAME'];            // FROM NAME: display name of user logged in
109
			} else {
110
				$this->FromName = $db_wbmailer_default_sendername;			// FROM NAME: set default name
111
			}
112
		}
113
		/* 
114
			some mail provider (lets say mail.com) reject mails send out by foreign mail 
115
			relays but using the providers domain in the from mail address (e.g. myname@mail.com)
116
		*/
117
		$this->From = $db_server_email;                           // FROM MAIL: (server mail)
118

    
119
		// set default mail formats
120
		$this->IsHTML(true);                                        
121
		$this->WordWrap = 80;                                       
122
		$this->Timeout = 30;
123
	}
124
}
(22-22/36)