Conditions | 4 |
Paths | 2 |
Total Lines | 48 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
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 | |||
58 |