1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PragmaRX\Health\Checkers; |
4
|
|
|
|
5
|
|
|
use PragmaRX\Health\Support\Result; |
6
|
|
|
use Illuminate\Support\Facades\Mail as IlluminateMail; |
7
|
|
|
|
8
|
|
|
class Mail extends Base |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Store mail configuration. |
12
|
|
|
* |
13
|
|
|
* @var |
14
|
|
|
*/ |
15
|
|
|
private $mailConfiguration; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Check resource. |
19
|
|
|
* |
20
|
|
|
* @return Result |
21
|
|
|
*/ |
22
|
1 |
|
public function check() |
23
|
|
|
{ |
24
|
1 |
|
return $this->checkMail(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Configure mail for testing. |
29
|
|
|
*/ |
30
|
1 |
|
private function configureMail() |
31
|
|
|
{ |
32
|
1 |
|
$this->mailConfiguration = config('mail'); |
33
|
|
|
|
34
|
1 |
|
config(['mail' => $this->target->config->toArray()]); |
|
|
|
|
35
|
1 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Send a test e-mail. |
39
|
|
|
*/ |
40
|
1 |
|
private function checkMail() |
41
|
|
|
{ |
42
|
1 |
|
$this->configureMail(); |
43
|
|
|
|
44
|
|
|
try { |
45
|
1 |
|
$this->sendMail(); |
46
|
|
|
|
47
|
1 |
|
$result = $this->makeHealthyResult(); |
48
|
|
|
} catch (\Exception $exception) { |
49
|
|
|
report($exception); |
50
|
|
|
|
51
|
|
|
$result = $this->makeResultFromException($exception); |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
$this->restoreMailConfiguration(); |
55
|
|
|
|
56
|
1 |
|
return $result; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Restore mail configuration. |
61
|
|
|
*/ |
62
|
1 |
|
private function restoreMailConfiguration() |
63
|
|
|
{ |
64
|
1 |
|
config(['mail' => $this->mailConfiguration]); |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Send a test e-mail message. |
69
|
|
|
*/ |
70
|
1 |
|
private function sendMail() |
71
|
|
|
{ |
72
|
|
|
IlluminateMail::send($this->target->view, [], function ($message) { |
|
|
|
|
73
|
1 |
|
$fromAddress = array_get($this->target->config, 'from.address'); |
|
|
|
|
74
|
|
|
|
75
|
1 |
|
$message->returnPath($fromAddress); |
76
|
|
|
|
77
|
1 |
|
$message->cc($fromAddress); |
78
|
|
|
|
79
|
1 |
|
$message->bcc($fromAddress); |
80
|
|
|
|
81
|
1 |
|
$message->replyTo($fromAddress); |
82
|
|
|
|
83
|
1 |
|
$message->to($this->target->to); |
|
|
|
|
84
|
|
|
|
85
|
1 |
|
$message->subject($this->target->subject); |
|
|
|
|
86
|
1 |
|
}); |
87
|
1 |
|
} |
88
|
|
|
} |
89
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.