-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.php
77 lines (59 loc) · 2.73 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
71
72
73
74
75
76
77
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
header('Content-Type: application/json');
$config = parse_ini_file("config.ini");
$emailBody = file_get_contents("email.html");
$response = array(
"result"=>"result");
function send_mail($recipientMail,$recipientFirstName, $recipientLastName, $procCorrelation,$gmailUser,$gmailPass,$emailBody)
{
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = $gmailUser;
$mail->Password = $gmailPass;
$mail->IsHTML(true);
$mail->AddAddress($recipientMail, $recipientFirstName.' '.$recipientLastName);
$mail->SetFrom("[email protected]", "Your Onboarding Companion");
$mail->AddReplyTo("[email protected]", "No Reply");
//$mail->AddCC("cc-recipient-email", "cc-recipient-name");
$mail->Subject = "This is your first day with us, ".$recipientFirstName;
$content = $emailBody;
$mail->MsgHTML($content);
if(!$mail->Send()) {
return "Error while sending Email.";
var_dump($mail);
} else {
return "Email sent successfully";
}
}
// get the HTTP method, path and body of the request
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
//$input = json_decode(file_get_contents('php://input'),true);
$input = json_decode(file_get_contents('php://input'));
$emailBody = str_replace("firstname",$input->firstName,$emailBody);
$emailBody = str_replace("lastname",$input->lastName,$emailBody);
//$urlToClick = $config['check_form_url']."/?FirstName=".$input->firstName."&LastName=".$input->lastName."&dwpHost=".$config['dwpHost']."&dwpPort=".$config['dwpPort']."&procCorr=".$input->procID;
//$urlToClick = "http:\\/\\/localhost:9090\\/forms\\/CompleteDetails\/CompleteDetails.php\/?FirstName=Adi&LastName=Lei&dwpHost=5e1d590a-227c-4f6b-8a30-58e76cf53551.mock.pstmn.io&dwpPort=443&procCorr=hihi";
$dwpHost = $config['dwpHost'];
$dwpPort = $config['dwpPort'];
$urltoClick = $config['check_form_url']."FirstName=".$input->firstName."&LastName=".$input->lastName."&dwpHost=".$dwpHost."&dwpPort=".$dwpPort."&procCorr=".$input->procID;
$emailBody = str_replace("http://laragon",$urltoClick,$emailBody);
switch ($method) {
case 'GET':
echo $input->param1;
case 'PUT':
case 'POST':
$response['result'] = send_mail($input->mail,$input->firstName,$input->lastName,$input->procID,$config['user'],$config['password'],$emailBody);
echo json_encode($response);
case 'DELETE':
}
?>