-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendMail.php
More file actions
143 lines (126 loc) · 5.39 KB
/
Copy pathSendMail.php
File metadata and controls
143 lines (126 loc) · 5.39 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of SendMail
*
* @author TI DST
*/
header("Access-Control-Allow-Origin: *");
require_once("./Rest.inc.php");
include("./PHPMailer-master/PHPMailerAutoload.php");
//include("./PHPMailer-master/class.smtp.php");
class SendMail extends REST {
//put your code here
private $_host = "smtp.gmail.com";
private $_port = 25;
private $_user = "noreply@onlinedst.com";
private $_pass = "0nl1n3DST";
private $Users_Accounts_Mails = array(
'SIMS@onlinedst.com',
'developer@onlinedst.com'
);
private $Users_Accounts_Password = array(
'9YBR<ngQD'/* pass to index 0 */,
'0nl1n3DST'
);
function __construct() {
$response = array('msg' => '', 'code' => 404);
$func = strtolower(trim(str_replace("/", "", $_REQUEST['rquest'])));
if ((int) method_exists($this, $func) > 0) {
foreach ($_REQUEST as $key => $value)
if ($key !== 'rquest')
$this->$key = $value;
$response = $this->$func();
}
$this->response($response['msg'], $response['code']);
}
public function SimpleSendInfo() {
$return = array('msg' => 'Correo de destino no aceptados.', 'code' => 200);
if (isset($this->addresses) && count($this->addresses) > 0) {
if (isset($this->from)) {
$this->_user = $this->from;
}
if (isset($this->UseAccount) && $this->UseAccount && array_search($this->from, $this->Users_Accounts_Mails)) {
$i = array_search($this->from, $this->Users_Accounts_Mails);
if (isset($this->Users_Accounts_Password[$i])) {
$this->_pass = $this->Users_Accounts_Password[$i];
}
}
$connectGmail = $this->connectGmail();
$connectGmail->From = $this->_user;
$connectGmail->FromName = $this->_user;
if (!isset($this->name)) {
$connectGmail->SetFrom($this->_user, 'SIMS');
$connectGmail->AddReplyTo($this->_user, 'SIMS');
} else {
$connectGmail->SetFrom(isset($this->fromName) ? $this->fromName : $this->_user, $this->name);
$connectGmail->AddReplyTo(isset($this->fromName) ? $this->fromName : $this->_user, $this->name);
}
if (!file_exists($this->attachment['path'])) {
file_put_contents('respinsefile', print_r($this->attachment, true));
}
if (isset($this->attachment) && isset($this->attachment['path']) && isset($this->attachment['file_name']) && file_exists($this->attachment['path']))
$connectGmail->AddAttachment($this->attachment['path'], $this->attachment['file_name']);
if ($this->attachmentURL && isset($this->attachmentURL['url']) && isset($this->attachmentURL['file_name']))
$connectGmail->addStringAttachment(file_get_contents($this->attachmentURL['url']), $this->attachmentURL['file_name']);
foreach ($this->addresses as $address)
$connectGmail->AddAddress($address, $address);
if (isset($this->addressesCC) && count($this->addressesCC) > 0)
foreach ($this->addressesCC as $address)
$connectGmail->addCC($address, $address);
if (isset($this->addressesBCC) && count($this->addressesBCC) > 0)
foreach ($this->addressesBCC as $address)
$connectGmail->addBCC($address, $address);
if (isset($this->message)) {
// file_put_contents("message", $this->message);
$connectGmail->Body = $this->message;
$connectGmail->MsgHTML($this->message);
if (isset($this->subject)) {
$connectGmail->Subject = $this->subject;
$status = $this->sendMail($connectGmail);
$return = array('msg' => $status, 'code' => 200);
} else
$return = array('msg' => 'ERROR: Mensaje sin asunto.', 'code' => 200);
} else
$return = array('msg' => 'ERROR: Mensaje vacio.', 'code' => 200);
}
return $return;
}
private function sendMail($connect) {
if (!$connect->Send()) {
return "ERROR: " . $connect->ErrorInfo;
} else {
return 'OK';
}
}
private function connectGmail() {
$mail = new PHPMailer();
// $mail->IsSMTP();
// $mail->Mailer="smtp";
$mail->IsHTML(true);
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Helo = "smtp.gmail.com";
$mail->Host = $this->_host;
$mail->Port = $this->_port;
$mail->Username = $this->_user;
$mail->Password = $this->_pass;
$mail->SMTPDebug = 2;
if (!isset($this->name)) {
$mail->AltBody = 'SIMS';
} else {
$mail->AltBody = $this->name;
}
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
//$mail->AddCustomHeader("Reply-to:{$this->_user}");
$mail->CharSet = "UTF-8";
$mail->WordWrap = 50;
return $mail;
}
}
new SendMail();