forked from opensource-socialnetwork/SMTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossn_com.php
More file actions
87 lines (85 loc) · 2.57 KB
/
ossn_com.php
File metadata and controls
87 lines (85 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Open Source Social Network
*
* @package Open Source Social Network
* @author Open Social Website Core Team <info@informatikon.com>
* @copyright 2014 iNFORMATIKON TECHNOLOGIES
* @license General Public Licence http://www.opensource-socialnetwork.org/licence
* @link http://www.opensource-socialnetwork.org
*/
define('__SMTP__', ossn_route()->com . 'SMTP/');
/**
* Initialize SMTP Component
*
* @return void
* @access private
*/
function ossn_com_smtp_init() {
ossn_add_hook('email', 'send:policy', 'ossn_smtp_deny', 1);
ossn_add_hook('email', 'send', 'ossn_smtp', 1);
ossn_register_com_panel('SMTP', 'settings');
if(ossn_isAdminLoggedin()) {
ossn_register_action('admin/smtp/settings/save', __SMTP__ . 'actions/admin/settings/save.php');
}
}
/**
* Stop the default send mail
*
* @return boolean
*/
function ossn_smtp_deny(){
return false;
}
/**
* Ossn SMTP
*
* Send notification emails using your smtp server
* Few hosting providers didn't have php mail() enabled,
* Users belong to this category can try this component.
*
* @return void|boolean
*/
function ossn_smtp($hook, $type, $mail, $return) {
$smtp = new OssnComponents;
$settings = $smtp->getSettings('SMTP');
if(!empty($settings->host) && !empty($settings->port) && !empty($settings->username) && !empty($settings->password)) {
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = $settings->host;
$mail->Port = $settings->port;
$mail->Username = $settings->username;
$mail->Password = $settings->password;
return $mail->send();
}
}
/**
* Check if is connected to server or not
*
* @return array
*/
function ossn_smtp_connected() {
$return = array();
$mail = new OssnMail;
$smtp = new OssnComponents;
$settings = $smtp->getSettings('SMTP');
$return['status'] = ossn_print("smtp:connectio:failed");
if(!empty($settings->host) && !empty($settings->port) && !empty($settings->username) && !empty($settings->password)) {
$mail->IsSMTP();
$mail->Timeout= 10; //timeout after 10 seconds
$mail->SMTPAuth = true;
$mail->Host = $settings->host;
$mail->Port = $settings->port;
$mail->Username = $settings->username;
$mail->Password = $settings->password;
if($mail->smtpConnect()) {
$mail->smtpClose();
$return['status'] = ossn_print("smtp:connection:connected");
} else {
$return['status'] = ossn_print("smtp:connectio:failed");
}
}
return $return;
}
//initilize ossn wall
ossn_register_callback('ossn', 'init', 'ossn_com_smtp_init');