Passed
Push — master ( 6b5ba2...27c0e5 )
by ma
01:42
created
src/Gateways/Smtp.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 namespace tinymeng\mailer\Gateways;
8 8
 use tinymeng\mailer\Connector\Gateway;
9 9
 
10
-class Smtp extends Gateway{
10
+class Smtp extends Gateway {
11 11
 
12 12
     /**
13 13
      * @var
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
     {
31 31
         $mail_from = $this->getAddress($this->stripComment($this->from_address));
32 32
         $body = preg_replace("/(^|(\r\n))(\.)/", "\1.\3", $body);
33
-        $this->boundary = "====" . md5(uniqid()) . "====";
34
-        $body = $this->prepareBody($body,$mailType);
33
+        $this->boundary = "====".md5(uniqid())."====";
34
+        $body = $this->prepareBody($body, $mailType);
35 35
         $header = $this->buildHeaders($subject, $mailType, $mail_from);
36 36
 
37 37
         // Prepare recipient list
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
         foreach ($TO as $rcpt_to) {
42 42
             $rcpt_to = $this->getAddress($rcpt_to);
43 43
             if (!$this->smtpSockopen($rcpt_to)) {
44
-                $this->logWrite("Error: Cannot send email to " . $rcpt_to . "\n");
44
+                $this->logWrite("Error: Cannot send email to ".$rcpt_to."\n");
45 45
                 $sent = false;
46 46
                 continue;
47 47
             }
48 48
             if ($this->smtpSend($this->host_name, $mail_from, $rcpt_to, $header, $body)) {
49
-                $this->logWrite("E-mail has been sent to <" . $rcpt_to . ">\n");
49
+                $this->logWrite("E-mail has been sent to <".$rcpt_to.">\n");
50 50
             } else {
51
-                $this->logWrite("Error: Cannot send email to <" . $rcpt_to . ">\n");
51
+                $this->logWrite("Error: Cannot send email to <".$rcpt_to.">\n");
52 52
                 $sent = false;
53 53
             }
54 54
             fclose($this->sock);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      * @return string
65 65
      * @author Tinymeng <[email protected]>
66 66
      */
67
-    private function buildHeaders($subject, $mailType, $mail_from){
67
+    private function buildHeaders($subject, $mailType, $mail_from) {
68 68
         // Set headers
69 69
         $header = "MIME-Version: 1.0\r\n";
70 70
         if (strtoupper($mailType) == "HTML") {
@@ -72,20 +72,20 @@  discard block
 block discarded – undo
72 72
         } else {
73 73
             $header .= "Content-Type: text/plain; charset=UTF-8\r\n";
74 74
         }
75
-        $header .= "To: " . $this->to_address . "\r\n";
75
+        $header .= "To: ".$this->to_address."\r\n";
76 76
         if (!empty($this->cc_address)) {
77
-            $header .= "Cc: " . $this->cc_address . "\r\n";
77
+            $header .= "Cc: ".$this->cc_address."\r\n";
78 78
         }
79
-        $header .= "From: $this->from_address <" . $this->from_address . ">\r\n";
80
-        $header .= "Subject: " . $subject . "\r\n";
81
-        if(!empty($this->headers)){
82
-            foreach ($this->headers as $head){
79
+        $header .= "From: $this->from_address <".$this->from_address.">\r\n";
80
+        $header .= "Subject: ".$subject."\r\n";
81
+        if (!empty($this->headers)) {
82
+            foreach ($this->headers as $head) {
83 83
                 $header .= $head;
84 84
             }
85 85
         }
86
-        $header .= "Date: " . date("r") . "\r\n";
87
-        $header .= "X-Mailer: By Redhat (PHP/" . phpversion() . ")\r\n";
88
-        $header .= "Message-ID: <" . date("YmdHis") . "." . uniqid() . "@" . $mail_from . ">\r\n";
86
+        $header .= "Date: ".date("r")."\r\n";
87
+        $header .= "X-Mailer: By Redhat (PHP/".phpversion().")\r\n";
88
+        $header .= "Message-ID: <".date("YmdHis").".".uniqid()."@".$mail_from.">\r\n";
89 89
         return $header;
90 90
     }
91 91
 
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
      * @return string
97 97
      * @author Tinymeng <[email protected]>
98 98
      */
99
-    private function prepareBody($body, $mailType){
99
+    private function prepareBody($body, $mailType) {
100 100
         if (strtoupper($mailType) == "HTML") {
101 101
             // Body with text and attachments
102
-            $body = "--$this->boundary\r\n" .
103
-                "Content-Type: text/html; charset=UTF-8\r\n" .
104
-                "Content-Transfer-Encoding: 7bit\r\n\r\n" .
105
-                $body . "\r\n";
102
+            $body = "--$this->boundary\r\n".
103
+                "Content-Type: text/html; charset=UTF-8\r\n".
104
+                "Content-Transfer-Encoding: 7bit\r\n\r\n".
105
+                $body."\r\n";
106 106
 
107
-            if(!empty($this->attachments)){
107
+            if (!empty($this->attachments)) {
108 108
                 foreach ($this->attachments as $attachment) {
109 109
                     $fileName = basename($attachment);
110 110
                     $fileContent = chunk_split(base64_encode(file_get_contents($attachment)));
111
-                    $body .= "--$this->boundary\r\n" .
112
-                        "Content-Type: application/octet-stream; name=\"$fileName\"\r\n" .
113
-                        "Content-Transfer-Encoding: base64\r\n" .
114
-                        "Content-Disposition: attachment; filename=\"$fileName\"\r\n\r\n" .
115
-                        $fileContent . "\r\n";
111
+                    $body .= "--$this->boundary\r\n".
112
+                        "Content-Type: application/octet-stream; name=\"$fileName\"\r\n".
113
+                        "Content-Transfer-Encoding: base64\r\n".
114
+                        "Content-Disposition: attachment; filename=\"$fileName\"\r\n\r\n".
115
+                        $fileContent."\r\n";
116 116
                 }
117 117
                 $this->attachments = array();
118 118
             }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
             return $this->smtpError("sending HELO command");
158 158
         }
159 159
         //auth
160
-        if($this->auth){
160
+        if ($this->auth) {
161 161
             if (!$this->smtpPutCmd("AUTH LOGIN", base64_encode($this->username))) {
162 162
                 return $this->smtpError("sending HELO command");
163 163
             }
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     private function smtpPutCmd($cmd, $arg = "")
309 309
     {
310 310
         if ($arg != "") {
311
-            if($cmd=="") $cmd = $arg;
311
+            if ($cmd == "") $cmd = $arg;
312 312
             else $cmd = $cmd." ".$arg;
313 313
         }
314 314
         fputs($this->sock, $cmd."\r\n");
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -308,8 +308,11 @@
 block discarded – undo
308 308
     private function smtpPutCmd($cmd, $arg = "")
309 309
     {
310 310
         if ($arg != "") {
311
-            if($cmd=="") $cmd = $arg;
312
-            else $cmd = $cmd." ".$arg;
311
+            if($cmd=="") {
312
+                $cmd = $arg;
313
+            } else {
314
+                $cmd = $cmd." ".$arg;
315
+            }
313 316
         }
314 317
         fputs($this->sock, $cmd."\r\n");
315 318
         $this->debug("> ".$cmd."\n");
Please login to merge, or discard this patch.
src/Connector/Gateway.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,20 +17,20 @@  discard block
 block discarded – undo
17 17
      * @author Tinymeng <[email protected]>
18 18
      * @date: 2019/9/26 15:21
19 19
      */
20
-    protected $host;        //发送email Host
21
-    protected $port;        //端口 25 or 456
22
-    protected $encryption;  //加密 ssl
23
-    protected $username;    //邮箱用户名(发送人email)
24
-    protected $password;    //邮箱密码(如果是第三方请去设置里获取)
25
-    protected $from_address;//发送人email
26
-
27
-    protected $to_address;   //接收人email
28
-    protected $cc_address;   //抄送人email
29
-    protected $bcc_address;  //隐性抄送人email
30
-
31
-    protected $log_file = false;//记录日志
20
+    protected $host; //发送email Host
21
+    protected $port; //端口 25 or 456
22
+    protected $encryption; //加密 ssl
23
+    protected $username; //邮箱用户名(发送人email)
24
+    protected $password; //邮箱密码(如果是第三方请去设置里获取)
25
+    protected $from_address; //发送人email
26
+
27
+    protected $to_address; //接收人email
28
+    protected $cc_address; //抄送人email
29
+    protected $bcc_address; //隐性抄送人email
30
+
31
+    protected $log_file = false; //记录日志
32 32
     protected $host_name = "localhost"; //is used in HELO command
33
-    protected $time_out = 30;//is used in fsockopen()
33
+    protected $time_out = 30; //is used in fsockopen()
34 34
 
35 35
     /**
36 36
      * 是否开启debug
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
             'from_address'=> '',
78 78
             'to_address'=> '',
79 79
         ];
80
-        $this->config = array_replace_recursive($_config,$config);
81
-        if(empty($this->config['from_address'])){
80
+        $this->config = array_replace_recursive($_config, $config);
81
+        if (empty($this->config['from_address'])) {
82 82
             $this->config['from_address'] = $this->config['username'];
83 83
         }
84
-        if(!empty($this->config['encryption'])){
85
-            $this->config['host'] = $this->config['encryption'] . '://' . $this->config['host'];
84
+        if (!empty($this->config['encryption'])) {
85
+            $this->config['host'] = $this->config['encryption'].'://'.$this->config['host'];
86 86
         }
87 87
 
88 88
         foreach ($this->config as $key => $value) {
89
-            if (property_exists($this,$key)) {
89
+            if (property_exists($this, $key)) {
90 90
                 $this->$key = $value;
91 91
             }
92 92
         }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      * @author Tinymeng <[email protected]>
120 120
      * @date: 2019/9/26 10:44
121 121
      */
122
-    public function setDebug($debug){
122
+    public function setDebug($debug) {
123 123
         $this->debug = $debug;
124 124
     }
125 125
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @author Tinymeng <[email protected]>
131 131
      * @date: 2019/9/26 15:20
132 132
      */
133
-    public function toEmail($email){
133
+    public function toEmail($email) {
134 134
         $this->to_address = $email;
135 135
         return $this;
136 136
     }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      * @author Tinymeng <[email protected]>
143 143
      * @date: 2019/9/26 15:20
144 144
      */
145
-    public function ccEmail($email){
145
+    public function ccEmail($email) {
146 146
         $this->cc_address = $email;
147 147
         return $this;
148 148
     }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      * @author Tinymeng <[email protected]>
155 155
      * @date: 2019/9/26 15:20
156 156
      */
157
-    public function bccEmail($email){
157
+    public function bccEmail($email) {
158 158
         $this->bcc_address = $email;
159 159
         return $this;
160 160
     }
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
      * @param array|string $attachments
165 165
      * @return $this
166 166
      */
167
-    public function addAttachments($attachments){
168
-        if(is_array($attachments)){
169
-            foreach ($attachments as $attachment){
170
-                if(file_exists($attachment)) $this->attachments[] = $attachment;
167
+    public function addAttachments($attachments) {
168
+        if (is_array($attachments)) {
169
+            foreach ($attachments as $attachment) {
170
+                if (file_exists($attachment)) $this->attachments[] = $attachment;
171 171
             }
172
-        }else{
173
-            if(file_exists($attachments)) $this->attachments[] = $attachments;
172
+        } else {
173
+            if (file_exists($attachments)) $this->attachments[] = $attachments;
174 174
         }
175 175
         return $this;
176 176
     }
@@ -180,10 +180,10 @@  discard block
 block discarded – undo
180 180
      * @param array|string $headers
181 181
      * @return $this
182 182
      */
183
-    public function addHeaders($headers){
184
-        if(is_array($headers)){
185
-            $this->headers = array_merge($this->headers,$headers);
186
-        }else{
183
+    public function addHeaders($headers) {
184
+        if (is_array($headers)) {
185
+            $this->headers = array_merge($this->headers, $headers);
186
+        } else {
187 187
             $this->headers[] = $headers;
188 188
         }
189 189
         return $this;
Please login to merge, or discard this patch.
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -167,10 +167,14 @@  discard block
 block discarded – undo
167 167
     public function addAttachments($attachments){
168 168
         if(is_array($attachments)){
169 169
             foreach ($attachments as $attachment){
170
-                if(file_exists($attachment)) $this->attachments[] = $attachment;
170
+                if(file_exists($attachment)) {
171
+                    $this->attachments[] = $attachment;
172
+                }
173
+            }
174
+        } else{
175
+            if(file_exists($attachments)) {
176
+                $this->attachments[] = $attachments;
171 177
             }
172
-        }else{
173
-            if(file_exists($attachments)) $this->attachments[] = $attachments;
174 178
         }
175 179
         return $this;
176 180
     }
@@ -183,7 +187,7 @@  discard block
 block discarded – undo
183 187
     public function addHeaders($headers){
184 188
         if(is_array($headers)){
185 189
             $this->headers = array_merge($this->headers,$headers);
186
-        }else{
190
+        } else{
187 191
             $this->headers[] = $headers;
188 192
         }
189 193
         return $this;
Please login to merge, or discard this patch.
src/Email.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
      */
22 22
     protected static function init($gateway, $config = null)
23 23
     {
24
-        $class = __NAMESPACE__ . '\\Gateways\\' . ucfirst(strtolower($gateway));
24
+        $class = __NAMESPACE__.'\\Gateways\\'.ucfirst(strtolower($gateway));
25 25
         if (class_exists($class)) {
26 26
             $app = new $class($config);
27 27
             return $app;
Please login to merge, or discard this patch.
example/sendmail.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@
 block discarded – undo
33 33
 $state = $email->sendmail( $mailtitle, $mailcontent, $mailtype);
34 34
 echo "<div style='width:300px; margin:36px auto;'>";
35 35
 if($state==""){
36
-	echo "对不起,邮件发送失败!请检查邮箱填写是否有误。";
37
-	echo "<a href='index.html'>点此返回</a>";
38
-	exit();
36
+    echo "对不起,邮件发送失败!请检查邮箱填写是否有误。";
37
+    echo "<a href='index.html'>点此返回</a>";
38
+    exit();
39 39
 }
40 40
 echo "恭喜!邮件发送成功!!";
41 41
 echo "<a href='index.html'>点此返回</a>";
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
 ];
17 17
 //******************** 配置信息 end ********************************
18 18
 
19
-$smtpemailto = $_POST['toemail'];//发送给谁
20
-$mailtitle = $_POST['title'];//邮件主题
21
-$mailcontent = "<h1>".$_POST['content']."</h1>";//邮件内容
19
+$smtpemailto = $_POST['toemail']; //发送给谁
20
+$mailtitle = $_POST['title']; //邮件主题
21
+$mailcontent = "<h1>".$_POST['content']."</h1>"; //邮件内容
22 22
 
23 23
 $email = Email::smtp($config);
24
-$email->setDebug(true);//线上注释此行
24
+$email->setDebug(true); //线上注释此行
25 25
 $email->toEmail($smtpemailto);
26 26
 $mailtype = "html";
27 27
 //$cc = "[email protected]";
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 //$email->addAttachments($attachments);//添加附件
31 31
 //$email->ccEmail($cc);//抄送人
32 32
 //$email->bccEmail($bcc);//隐性抄送人
33
-$state = $email->sendmail( $mailtitle, $mailcontent, $mailtype);
33
+$state = $email->sendmail($mailtitle, $mailcontent, $mailtype);
34 34
 echo "<div style='width:300px; margin:36px auto;'>";
35
-if($state==""){
35
+if ($state == "") {
36 36
 	echo "对不起,邮件发送失败!请检查邮箱填写是否有误。";
37 37
 	echo "<a href='index.html'>点此返回</a>";
38 38
 	exit();
Please login to merge, or discard this patch.