MailSmtp   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 28
c 4
b 0
f 0
dl 0
loc 50
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A send() 0 48 4
1
<?php
2
namespace GJClasses;
3
4
class MailSmtp
5
{
6
    public function send($from_name, $from_address, $reply_name, $reply_address, $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 = GJC_EMAIL_ENCODING_TYPE;
14
        $mail->SMTPSecure = GJC_SMTP_PROTOCOL;
15
        $mail->Host = GJC_SMTP_MAIL_SERVER;
16
        $mail->Port = GJC_SMTP_PORT;
17
        $mail->SMTPAuth = GJC_SMTP_AUTHENTICATION_ON;
18
        $mail->Username = GJC_SMTP_USERNAME;
19
        $mail->Password = GJC_SMTP_PASSWORD;
20
        $mail->setFrom($from_address, $from_name);
21
        $mail->addReplyTo($reply_address, $reply_name);
22
23
        if ($recipients) {
24
25
            $result_message = 'Email Send Failed';
26
27
            foreach ($recipients AS $recipient) {
28
29
                $mail->Subject = $subject;
30
                $mail->Body = $message_html;
31
                $mail->AltBody = $message_text;
32
                $mail->clearAddresses();
33
                $mail->addAddress($recipient);
34
35
                if ($mail->send()) {
36
37
                    $result_message = 'Email Send Succeeded';
38
39
                } else {
40
41
                    $result_message = 'Email Send Failed';
42
43
                }
44
45
            }
46
47
        } else {
48
49
            $result_message = 'Nothing to send';
50
51
        }
52
53
        return $result_message;
54
55
    }
56
57
}
58