Passed
Push — master ( 1686c2...b114f1 )
by Greg
02:17
created

Smtp   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A send() 0 38 3
1
<?php
2
namespace GJClasses;
3
4
class Smtp
5
{
6
    public function send($recipients, $subject, $message_html, $message_text)
7
    {
8
        $mail = new \PHPMailer();
9
10
        // $mail->SMTPDebug = 3;
11
        $mail->isSMTP();
12
        $mail->isHTML(true);
13
        $mail->CharSet = EMAIL_ENCODING_TYPE;
14
        $mail->SMTPSecure = SMTP_PROTOCOL;
15
        $mail->Host = SMTP_MAIL_SERVER;
16
        $mail->Port = SMTP_PORT;
17
        $mail->SMTPAuth = SMTP_AUTHENTICATION_ON;
18
        $mail->Username = SMTP_USERNAME;
19
        $mail->Password = SMTP_PASSWORD;
20
        $mail->setFrom(SMTP_FROM_ADDRESS, SMTP_FROM_NAME);
21
        $mail->addReplyTo(SMTP_REPLY_ADDRESS, SMTP_REPLY_NAME);
22
23
        foreach ($recipients AS $recipient) {
24
25
            $mail->Subject = $subject;
26
            $mail->Body = $message_html;
27
            $mail->AltBody = $message_text;
28
            $mail->clearAddresses();
29
            $mail->addAddress($recipient);
30
31
            if ($mail->send()) {
32
33
                $result_message = 'Email Send Succeeded';
34
35
            } else {
36
37
                $result_message = 'Email Send Failed';
38
39
            }
40
41
        }
42
43
        return $result_message;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result_message seems to be defined by a foreach iteration on line 23. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
44
45
    }
46
}
47