Project

General

Profile

1
<?php
2

    
3
// $Id: class.wbmailer.php 1495 2011-08-11 15:53:59Z 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 access directly
27
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
28

    
29
// Include PHPMailer class
30
require_once(WB_PATH."/include/phpmailer/class.phpmailer.php");
31

    
32
class wbmailer extends PHPMailer 
33
{
34
	// new websitebaker mailer class (subset of PHPMailer class)
35
	// setting default values 
36

    
37
	function wbmailer() {
38
		global $database;
39
		// set mailer defaults (PHP mail function)
40
		$db_wbmailer_routine = "phpmail";
41
		$db_wbmailer_smtp_host = "";
42
		$db_wbmailer_default_sendername = "WB Mailer";
43
		$db_server_email = SERVER_EMAIL;
44

    
45
		// get mailer settings from database
46
		// $database = new database();
47
		$query = "SELECT * FROM " .TABLE_PREFIX. "settings";
48
		$results = $database->query($query);
49
		while($setting = $results->fetchRow()) {
50
			if ($setting['name'] == "wbmailer_routine") { $db_wbmailer_routine = $setting['value']; }
51
			if ($setting['name'] == "wbmailer_smtp_host") { $db_wbmailer_smtp_host = $setting['value']; }
52
			if ($setting['name'] == "wbmailer_smtp_auth") { $db_wbmailer_smtp_auth = (bool)$setting['value']; }
53
			if ($setting['name'] == "wbmailer_smtp_username") { $db_wbmailer_smtp_username = $setting['value']; }
54
			if ($setting['name'] == "wbmailer_smtp_password") { $db_wbmailer_smtp_password = $setting['value']; }
55
			if ($setting['name'] == "wbmailer_default_sendername") { $db_wbmailer_default_sendername = $setting['value']; }
56
			if ($setting['name'] == "server_email") { $db_server_email = $setting['value']; }
57
		}
58

    
59
		// set method to send out emails
60
		if($db_wbmailer_routine == "smtp" AND strlen($db_wbmailer_smtp_host) > 5) {
61
			// use SMTP for all outgoing mails send by Website Baker
62
			$this->IsSMTP();                                            
63
			$this->Host = $db_wbmailer_smtp_host;
64
			// check if SMTP authentification is required
65
			if ($db_wbmailer_smtp_auth == "true" && strlen($db_wbmailer_smtp_username) > 1 && strlen($db_wbmailer_smtp_password) > 1) {
66
				// use SMTP authentification
67
				$this->SMTPAuth = true;     	  								// enable SMTP authentification
68
				$this->Username = $db_wbmailer_smtp_username;  	// set SMTP username
69
				$this->Password = $db_wbmailer_smtp_password;	  // set SMTP password
70
			}
71
		} else {
72
			// use PHP mail() function for outgoing mails send by Website Baker
73
			$this->IsMail();
74
		}
75

    
76
		// set language file for PHPMailer error messages
77
		if(defined("LANGUAGE")) {
78
			$this->SetLanguage(strtolower(LANGUAGE),"language");    // english default (also used if file is missing)
79
		}
80

    
81
		// set default charset
82
		if(defined('DEFAULT_CHARSET')) { 
83
			$this->CharSet = DEFAULT_CHARSET; 
84
		} else {
85
			$this->CharSet='utf-8';
86
		}
87

    
88
		// set default sender name
89
		if($this->FromName == 'Root User') {
90
			if(isset($_SESSION['DISPLAY_NAME'])) {
91
				$this->FromName = $_SESSION['DISPLAY_NAME'];            // FROM NAME: display name of user logged in
92
			} else {
93
				$this->FromName = $db_wbmailer_default_sendername;			// FROM NAME: set default name
94
			}
95
		}
96

    
97
		/* 
98
			some mail provider (lets say mail.com) reject mails send out by foreign mail 
99
			relays but using the providers domain in the from mail address (e.g. myname@mail.com)
100
		*/
101
		$this->From = $db_server_email;                           // FROM MAIL: (server mail)
102

    
103
		// set default mail formats
104
		$this->IsHTML(true);                                        
105
		$this->WordWrap = 80;                                       
106
		$this->Timeout = 30;
107
	}
108
}
(12-12/19)