webshelf /
framework
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: Mark |
||
| 5 | * Date: 16/10/2016 |
||
| 6 | * Time: 14:34. |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace App\Classes; |
||
| 10 | |||
| 11 | use Mail; |
||
| 12 | use App\Model\Account; |
||
| 13 | |||
| 14 | class Email |
||
| 15 | { |
||
| 16 | public $from; |
||
| 17 | /** @var Account */ |
||
| 18 | public $to; |
||
| 19 | public $cc; |
||
| 20 | public $bcc; |
||
| 21 | public $header; |
||
| 22 | public $subject; |
||
| 23 | public $message; |
||
| 24 | |||
| 25 | // store special items for the email to use. |
||
| 26 | public $content = []; |
||
| 27 | |||
| 28 | public function to(Account $account) |
||
| 29 | { |
||
| 30 | $this->to = $account; |
||
| 31 | |||
| 32 | return $this; |
||
| 33 | } |
||
| 34 | |||
| 35 | public function header($message) |
||
| 36 | { |
||
| 37 | $this->header = $message; |
||
| 38 | |||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function from($email) |
||
| 43 | { |
||
| 44 | $this->from = $email; |
||
| 45 | |||
| 46 | return $this; |
||
| 47 | } |
||
| 48 | |||
| 49 | public function subject($title) |
||
| 50 | { |
||
| 51 | $this->subject = $title; |
||
| 52 | |||
| 53 | return $this; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function message($message) |
||
| 57 | { |
||
| 58 | $this->message = $message; |
||
| 59 | |||
| 60 | return $this; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Attach a value to the email message. |
||
| 65 | * |
||
| 66 | * @param $key |
||
| 67 | * @param $value |
||
| 68 | * @return $this |
||
| 69 | */ |
||
| 70 | public function with($key, $value) |
||
| 71 | { |
||
| 72 | $this->content[$key] = $value; |
||
| 73 | |||
| 74 | return $this; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function send($view) |
||
| 78 | { |
||
| 79 | $from = $this->from ?: '[email protected]'; |
||
| 80 | $header = $this->header ?: 'Coffeebreak CMS'; |
||
| 81 | $this->to = $this->to ?: account(); |
||
| 82 | |||
| 83 | Mail::send($view, ['email' => $this], function ($m) use ($header, $from) { |
||
| 84 | $m->from($from, $header); |
||
| 85 | |||
| 86 | $m->to($this->to->email())->subject($this->subject." on '".tenant()->domain."'"); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 87 | }); |
||
| 88 | } |
||
| 89 | } |
||
| 90 |