-
Notifications
You must be signed in to change notification settings - Fork 4
/
mailer.php
70 lines (55 loc) · 1.81 KB
/
mailer.php
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
<?php
header('Content-Type: application/json');
$aResult = array();
if( !isset($_POST['functionname']) ) { $aResult['error'] = 'No function name!'; }
if( !isset($_POST['arguments']) ) { $aResult['error'] = 'No function arguments!'; }
if( !isset($aResult['error']) ) {
switch($_POST['functionname']) {
case 'sendgmail':
if( !is_array($_POST['arguments']) || (count($_POST['arguments']) < 2) ) {
$aResult['error'] = 'Error in arguments!';
}
else {
$aResult['result'] = sendgmail($_POST['arguments'][0], $_POST['arguments'][1]);
}
break;
default:
$aResult['error'] = 'Not found function '.$_POST['functionname'].'!';
break;
}
}
echo json_encode($aResult);
function sendgmail($addr, $body) {
$config = parse_ini_file('../../catchit/email_config.ini');
require_once("phpmailer/class.phpmailer.php");
include("phpmailer/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = $config['address'];
$mail->Password = $config['password'];
$mail->Priority = 3;
$mail->CharSet = 'UTF-8';
$mail->Encoding = '8bit';
$mail->Subject = 'Data from Catchit';
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->From = $config['address'];
$mail->FromName = 'Catchit';
$mail->WordWrap = 900;
$mail->AddAddress($addr);
$mail->isHTML( FALSE );
$mail->Body = $body;
$mail->Send();
$mail->SmtpClose();
if ( $mail->IsError() ) {
return 'failed to send';
}
else {
return 'Email has been sent';
}
}
?>