ContactMailer.php 1.52 KB
<?php

namespace FootyRoom\Services\Feedback;

use FootyRoom\Core\CoreException;
use Illuminate\Contracts\Mail\Mailer;

class ContactMailer
{
    /**
     * @var \Illuminate\Contracts\Mail\Mailer
     */
    protected $mailer;

    /**
     * Constructor.
     *
     * @param \Illuminate\Contracts\Mail\Mailer $mailer
     */
    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    /**
     * Send the feedback email.
     *
     * @param string $contactName
     * @param string $contactEmail
     * @param string $company
     * @param string $message
     */
    public function sendFeedback($contactName, $contactEmail, $company, $message)
    {
        if ($contactName == '') {
            throw new CoreException('Please give us your name.');
        }

        if (!filter_var($contactEmail, FILTER_VALIDATE_EMAIL)) {
            throw new CoreException('Please input a valid email.');
        }

        if ($message == '') {
            throw new CoreException('Please enter your message.');
        }

        $this->mailer->send(
            'emails.feedback',
            [
                'contactName' => $contactName,
                'contactEmail' => $contactEmail,
                'company' => $company,
                'msg' => $message,
            ],
            function ($m) use ($contactEmail) {
                $m->from($contactEmail, 'FootyRoom');
                $m->to('info@footyroom.com', 'FootyRoom');
                $m->subject('FootyRoom Mail');
            }
        );
    }
}