forked from htmlacademy-php1/1622797-yeticave-14
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetwinner.php
43 lines (33 loc) · 1.15 KB
/
getwinner.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
<?php
/**
* @var mysqli $link
* @var mysqli $config
*/
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Email;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/init.php';
$base_url = $config['base_url'];
$dsn = 'smtp://21225020ba29e9:[email protected]:2525?encryption=tls&auth_mode=login';
$transport = Transport::fromDsn($dsn);
$lots = get_lots_whithout_winners($link);
$last_bets_lots = [];
foreach ($lots as $lot) {
$last_bets_lots[] = get_last_bets($link, $lot['lot_id']);
}
$last_bets_lots = array_filter($last_bets_lots);
foreach ($last_bets_lots as $last_bets) {
add_winner_lot($link, $last_bets['user_id'], $last_bets['lot_id']);
}
$winners = $last_bets_lots;
$mailer = new Mailer($transport);
$message = new Email();
$message->subject("Ваша ставка победила");
$message->from("[email protected]");
foreach ($winners as $winner) {
$message->to($winner['email']);
$message_content = include_template('email.php', ['winner' => $winner, 'base_url' => $base_url]);
$message->html($message_content);
$mailer->send($message);
}