-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-queue.php
More file actions
67 lines (50 loc) · 1.7 KB
/
email-queue.php
File metadata and controls
67 lines (50 loc) · 1.7 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
<?php
require_once "lib/config.inc.php";
$result = array();
$result['success'] = 1;
$result['message'] = "";
try{
print_r($_REQUEST);
$token = isset($_REQUEST['token'])?$_REQUEST['token']:'';
$to_name = isset($_REQUEST['to_name'])?$_REQUEST['to_name']:'';
$to_email = isset($_REQUEST['to_email'])?$_REQUEST['to_email']:'';
$subject = isset($_REQUEST['subject'])?$_REQUEST['subject']:'';
$body_txt = isset($_REQUEST['body_txt'])?$_REQUEST['body_txt']:'';
$body_html = isset($_REQUEST['body_html'])?$_REQUEST['body_html']:'';
$auth = isset($_REQUEST['auth'])?$_REQUEST['auth']:'';
$local_auth = md5("EMAIL:".$to_email.":MD5:SUBJECT:".$subject.$token);
echo $auth." - ".$local_auth;
if($auth != $local_auth){
throw new Exception("Invalid Auth");
}
if(!filter_var($to_email, FILTER_VALIDATE_EMAIL)){
throw new Exception("Invalid Email ID", 1);
}
if(trim($subject) == ""){
throw new Exception("Missing Subject");
}
if(trim($body_html) == "" && trim($body_txt) == ""){
throw new Exception("Missing Body Message");
}
$res = $db->fetchRow("select * from `mailer` where `token` = ?", array($token));
if(is_array($res) && isset($res['id'])){
if($res['status'] == 0){
throw new Exception("Account is not active");
}
}else{
throw new Exception("Invalid Account");
}
$mailer_id = $res['id'];
$mailqueue = new MailQueue();
$id = $mailqueue->add($mailer_id, $to_name, $to_email, $subject, $body_txt, $body_html);
if($id > 0){
$result['queue_id'] = $id;
$result['message'] = "Successfully Added to Mail Queue";
}else{
throw new Exception("Failed Adding to Queue");
}
}catch(Exception $e){
$result['success'] = 0;
$result['message'] = $e->getMessage();
}
echo json_encode($result);