public function getSendingType(): ?string
{
return $this->sending_type;
}
public function setSendingType(string $sending_type): self
{
$this->sending_type = $sending_type;
return $this;
}
require '/var/www/project/includes/model.php';
require '/var/www/project/vendor/autoload.php';
use Aws\Ses\SesClient;
use Aws\Exception\AwsException;
$key = '';
$secret = '';
$SesClient = new SesClient([
'version' => '2010-12-01',
'region' => 'us-east-2',
'credentials' => [
'key' => $key,
'secret' => $secret,
]
]);
$allUsers = R::findAll('users');
$date = date_create(date("Y-m-d H:i:s"));
$day = date_format($date, 'l');
$timeNow = date("H:i");
echo '<br><br>';
$sql = 'SELECT * FROM users, bookmarks
WHERE bookmarks.author_id = users.id
AND bookmarks.is_sending = false';
$rows = R::getAll($sql);
$authors = R::convertToBeans('users', $rows);
$groupedData = [];
foreach ($authors as $author) {
$groupedData[$author->login][] = $author->name;
}
foreach ($groupedData as $login => $names) {
$sender_email = 'protocarpool@gmail.com';
$recipient_emails = [$login];
$subject = json_encode($login);
$plaintext_body = implode(", <br>", $names);
$html_body = 'test';
$char_set = 'UTF-8';
try {
$result = $SesClient->sendEmail([
'Destination' => [
'ToAddresses' => $recipient_emails,
],
'ReplyToAddresses' => [$sender_email],
'Source' => $sender_email,
'Message' => [
'Body' => [
'Html' => [
'Charset' => $char_set,
'Data' => $plaintext_body,
],
'Text' => [
'Charset' => $char_set,
'Data' => $plaintext_body,
],
],
'Subject' => [
'Charset' => $char_set,
'Data' => $subject,
],
],
]);
$messageId = $result['MessageId'];
echo("Email sent! Message ID: $messageId" . "\n");
} catch (AwsException $e) {
echo $e->getMessage();
echo("The email was not sent. Error message: " . $e->getAwsErrorMessage() . "\n");
echo "\n";
}
}