HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/demo.sports-crowd.com/vendor/mailersend/mailersend/src/Endpoints/Email.php
<?php

namespace MailerSend\Endpoints;

use Assert\Assertion;
use MailerSend\Helpers\Builder\Attachment;
use MailerSend\Helpers\Builder\EmailParams;
use MailerSend\Helpers\Builder\Recipient;
use MailerSend\Helpers\Builder\Variable;
use MailerSend\Helpers\GeneralHelpers;
use Tightenco\Collect\Support\Collection;

class Email extends AbstractEndpoint
{
    protected string $endpoint = 'email';

    /**
     * @throws \JsonException
     * @throws \MailerSend\Exceptions\MailerSendAssertException
     * @throws \Psr\Http\Client\ClientExceptionInterface
     */
    public function send(EmailParams $params): array
    {
        GeneralHelpers::assert(fn() => Assertion::notEmpty(array_filter([
            $params->getTemplateId(), $params->getHtml(), $params->getText()
        ], fn($v) => $v !== null), 'One of template_id, html or text must be supplied'));

        if (!$params->getTemplateId()) {
            GeneralHelpers::assert(fn() => Assertion::email($params->getFrom()) &&
                Assertion::minLength($params->getFromName(), 1) &&
                Assertion::minLength($params->getSubject(), 1) &&
                Assertion::minCount($params->getRecipients(), 1)
            );
        } else {
            GeneralHelpers::assert(fn() => Assertion::minCount($params->getRecipients(), 1));
        }

        $recipients_mapped = (new Collection($params->getRecipients()))->map(fn($v) => is_object($v) && is_a($v,
            Recipient::class) ? $v->toArray() : $v)->toArray();
        $attachments_mapped = (new Collection($params->getAttachments()))->map(fn($v) => is_object($v) && is_a($v,
            Attachment::class) ? $v->toArray() : $v)->toArray();
        $variables_mapped = (new Collection($params->getVariables()))->map(fn($v) => is_object($v) && is_a($v,
            Variable::class) ? $v->toArray() : $v)->toArray();

        return $this->httpLayer->post(
            $this->buildUri($this->endpoint),
            array_filter([
                'from' => [
                    'email' => $params->getFrom(),
                    'name' => $params->getFromName(),
                ],
                'reply_to' => [
                    'email' => $params->getReplyTo(),
                    'name' => $params->getReplyToName(),
                ],
                'to' => $recipients_mapped,
                'subject' => $params->getSubject(),
                'template_id' => $params->getTemplateId(),
                'text' => $params->getText(),
                'html' => $params->getHtml(),
                'tags' => $params->getTags(),
                'attachments' => $attachments_mapped,
                'variables' => $variables_mapped
            ], fn($v) => is_array($v) ? array_filter($v, fn($v) => $v !== null) : $v !== null
            ));
    }
}