Blame view

app/Services/Contact/ContactMailer.php 1.52 KB
e77200db5   nologostudio.ru   Initial commit
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
  <?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');
              }
          );
      }
  }