Passed
Push — master ( 7383db...8c584c )
by Ferry
03:24
created

MailHelper::subject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 3/13/2019
6
 * Time: 12:51 AM
7
 */
8
9
namespace crocodicstudio\crudbooster\helpers;
10
11
use Illuminate\Support\Facades\Mail;
12
13
class MailHelper
14
{
15
16
    private $content;
17
    private $sender_email;
18
    private $sender_name;
19
    private $to_email;
20
    private $cc_email;
21
    private $attachments;
22
    private $subject;
23
24
    public function sender($email, $name) {
25
        $this->sender_email = $email;
26
        $this->sender_name = $name;
27
    }
28
29
    public function subject($subject) {
30
        $this->subject = $subject;
31
    }
32
33
    public function content($content) {
34
        $this->content = $content;
35
    }
36
37
    public function to($email, $cc_email = null) {
38
        $this->to_email = $email;
39
        $this->cc_email = $cc_email;
40
    }
41
42
    public function addAttachment($url) {
43
        $this->attachments[] = $url;
44
    }
45
46
    public function send() {
47
        Mail::send("crudbooster::emails.blank", ['content' => $this->content], function ($message) {
48
            $message->priority(1);
49
            $message->to($this->to_email);
50
            $message->from($this->sender_email, $this->sender_name);
51
52
            if (isset($this->cc_email)) {
53
                $message->cc($this->cc_email);
54
            }
55
56
            if (isset($this->attachments) && count($this->attachments)) {
57
                foreach ($this->attachments as $attachment) {
58
                    $message->attach($attachment);
59
                }
60
            }
61
62
            $message->subject($this->subject);
63
        });
64
    }
65
}