Pleets /
dronephp
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * DronePHP (http://www.dronephp.com) |
||
| 4 | * |
||
| 5 | * @link http://github.com/Pleets/DronePHP |
||
| 6 | * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org) |
||
| 7 | * @license http://www.dronephp.com/license |
||
| 8 | * @author Darío Rivera <[email protected]> |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace Drone\Pear; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Mail class |
||
| 15 | * |
||
| 16 | * Helper class to send emails |
||
| 17 | */ |
||
| 18 | class Mail |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Mail host |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $host; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Failure messages |
||
| 29 | * |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $errors = []; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Returns the host attribute |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | public function getHost() |
||
| 40 | { |
||
| 41 | return $this->host; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Returns an array with all failure messages |
||
| 46 | * |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | public function getErrors() |
||
| 50 | { |
||
| 51 | return $this->errors; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Sets host attribute |
||
| 56 | * |
||
| 57 | * @param string $value |
||
| 58 | * |
||
| 59 | * @return null |
||
| 60 | */ |
||
| 61 | public function setHost($value) |
||
| 62 | { |
||
| 63 | $this->host = $value; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Constructor |
||
| 68 | * |
||
| 69 | * |
||
| 70 | * @param array $options |
||
| 71 | * @throws RuntimeException |
||
| 72 | */ |
||
| 73 | public function __construct() |
||
| 74 | { |
||
| 75 | @include_once 'System.php'; |
||
| 76 | |||
| 77 | if (!class_exists('System', false)) { |
||
| 78 | throw new \RuntimeException("PEAR is not installed in your system!"); |
||
| 79 | } |
||
| 80 | |||
| 81 | include_once 'Net/SMTP.php'; |
||
| 82 | |||
| 83 | if (!class_exists('\Net_SMTP', false)) { |
||
| 84 | throw new \RuntimeException("PEAR::Net_SMTP is not installed!"); |
||
| 85 | } |
||
| 86 | |||
| 87 | @include_once 'Mail.php'; |
||
| 88 | |||
| 89 | if (!class_exists('\Mail', false)) { |
||
| 90 | throw new \RuntimeException("PEAR::Mail is not installed!"); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Adds an error |
||
| 96 | * |
||
| 97 | * @param string $code |
||
| 98 | * @param string $message |
||
| 99 | * |
||
| 100 | * @return null |
||
| 101 | */ |
||
| 102 | protected function error($code, $message = null) |
||
| 103 | { |
||
| 104 | if (!array_key_exists($code, $this->errors)) { |
||
| 105 | $this->errors[$message] = |
||
| 106 | (is_null($message) && array_key_exists($code, $this->errors)) |
||
| 107 | ? $this->errors[$code] |
||
| 108 | : $message; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Sends an email |
||
| 114 | * |
||
| 115 | * @param string $from |
||
| 116 | * @param string $to |
||
| 117 | * @param string $subject |
||
| 118 | * @param string $body |
||
| 119 | * |
||
| 120 | * @return boolean |
||
| 121 | */ |
||
| 122 | public function send($from, $to, $subject, $body) |
||
| 123 | { |
||
| 124 | $headers = [ |
||
| 125 | 'From' => $from, |
||
| 126 | 'To' => $to, |
||
| 127 | 'Subject' => $subject, |
||
| 128 | 'Content-type' => 'text/html;charset=iso-8859-1', |
||
| 129 | ]; |
||
| 130 | |||
| 131 | $smtp = \Mail::factory( |
||
|
0 ignored issues
–
show
|
|||
| 132 | 'smtp', |
||
| 133 | ['host' => $this->host, 'auth' => false] |
||
| 134 | ); |
||
| 135 | |||
| 136 | $mail = $smtp->send($to, $headers, $body); |
||
| 137 | |||
| 138 | if (\PEAR::isError($mail)) { |
||
|
0 ignored issues
–
show
The type
PEAR was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 139 | $this->error( |
||
| 140 | $mail->getCode(), |
||
| 141 | $mail->getMessage() |
||
| 142 | ); |
||
| 143 | |||
| 144 | return false; |
||
| 145 | } |
||
| 146 | |||
| 147 | return true; |
||
| 148 | } |
||
| 149 | } |
||
| 150 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths