Project

General

Profile

1
<?php
2

    
3
// $Id: class.WbMailer.php 2064 2014-01-01 15:09:58Z 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
class WbMailer extends PHPMailer
27
{
28
	// new websitebaker mailer class (subset of PHPMailer class)
29
	// setting default values 
30

    
31
	function __construct() {
32

    
33
        $oDb = WbDatabase::getInstance();
34
		// set mailer defaults (PHP mail function)
35
		$db_wbmailer_routine = "phpmail";
36
		$db_wbmailer_smtp_host = "";
37
		$db_wbmailer_default_sendername = "WB Mailer";
38
		$db_server_email = SERVER_EMAIL;
39

    
40
		// get mailer settings from database
41
		// $database = new database();
42
		$query = 'SELECT * FROM `'.$oDb->TablePrefix.'settings`';
43
		$oSettingSet = $oDb->doQuery($query);
44
		while($aSettings = $oSettingSet->fetchRow(MYSQL_ASSOC)) {
45
            switch ($aSettings['name']):
46
                case 'wbmailer_routine':
47
                    $db_wbmailer_routine = $aSettings['value']; break;
48
                case 'wbmailer_smtp_host':
49
                    $db_wbmailer_smtp_host = $aSettings['value']; break;
50
                case 'wbmailer_smtp_auth':
51
                    $db_wbmailer_smtp_auth = (bool)$aSettings['value']; break;
52
                case 'wbmailer_smtp_username':
53
                    $db_wbmailer_smtp_username = $aSettings['value']; break;
54
                case 'wbmailer_smtp_password':
55
                    $db_wbmailer_smtp_password = $aSettings['value']; break;
56
                case 'wbmailer_default_sendername':
57
                    $db_wbmailer_default_sendername = $aSettings['value']; break;
58
                case 'server_email':
59
                    $db_server_email = $aSettings['value']; break;
60
                default:
61
                    break;
62
            endswitch;
63
		}
64

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

    
82
		// set language file for PHPMailer error messages
83
		if(defined("LANGUAGE")) {
84
			$this->SetLanguage(strtolower(LANGUAGE),"language");    // english default (also used if file is missing)
85
		}
86

    
87
		// set default charset
88
		if(defined('DEFAULT_CHARSET')) { 
89
			$this->CharSet = DEFAULT_CHARSET; 
90
		} else {
91
			$this->CharSet='utf-8';
92
		}
93

    
94
		// set default sender name
95
		if($this->FromName == 'Root User') {
96
			if(isset($_SESSION['DISPLAY_NAME'])) {
97
				$this->FromName = $_SESSION['DISPLAY_NAME'];            // FROM NAME: display name of user logged in
98
			} else {
99
				$this->FromName = $db_wbmailer_default_sendername;			// FROM NAME: set default name
100
			}
101
		}
102
		/* 
103
			some mail provider (lets say mail.com) reject mails send out by foreign mail 
104
			relays but using the providers domain in the from mail address (e.g. myname@mail.com)
105
		*/
106
		$this->From = $db_server_email;                           // FROM MAIL: (server mail)
107

    
108
		// set default mail formats
109
		$this->IsHTML(true);                                        
110
		$this->WordWrap = 80;                                       
111
		$this->Timeout = 30;
112
	}
113
}
(25-25/38)