-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawsS3.php
70 lines (53 loc) · 1.81 KB
/
awsS3.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
<?php
namespace Classes\AWS;
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
class awsS3
{
private $bucket = 'raas-assets-dev';
private $keyname = 'email-template/PSENEST.html';
public $s3;
CONST FROM_EMAIL = '[email protected]';
CONST TO_SUBJECT = 'MARAAS instant rebate offer';
private $emailVars =[
'%FIRSTNAME%' => 'firstname',
'%LASTNAME%' => 'lastname',
'%COUPONCODE%'=> 'couponCode',
'%URL%' => 'rebateUrl1'
];
public function __construct()
{
$this->s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
}
public function getData()
{
try {
$result = $this->s3->getObject([
'Bucket' => $this->bucket,
'Key' => $this->keyname
]);
header("Content-Type: {$result['ContentType']}");
return $result['Body'];
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}
public function sendMail($res, $contents)
{
$firstname = ($res['firstName']) ? $res['firstName'] :$res['firstname'];
$lastname = ($res['lastName']) ? $res['lastName'] :$res['lastname'];
$contents = str_replace("%FIRSTNAME%", $firstname, $contents);
$contents = str_replace("%LASTNAME%", $lastname, $contents);
$contents = str_replace("%URL%", $res['rebateUrl1'], $contents);
$contents = str_replace("%COUPONCODE%", $res['couponCode'], $contents);
$to = self::FROM_EMAIL;
$subject = self::TO_SUBJECT;
$message = $contents;
$headers = 'From:'.self::FROM_EMAIL.'' . "\r\n" .
'Reply-To: '.self::FROM_EMAIL . "\r\nContent-type: text/html";
// mail($to, $subject, $message, $headers);
}
}