22
33namespace justcoded \form2email \Mailer ;
44
5-
5+ use justcoded \ form2email \ DataObject \ DataObject ;
66use justcoded \form2email \Message \Message ;
77use PHPMailer \PHPMailer \PHPMailer ;
88use PHPMailer \PHPMailer \Exception ;
99
10- class PhpHandlerSend
10+ class PhpHandlerSend extends DataObject
1111{
12- protected $ message ;
13-
14- protected $ host ;
15-
16- protected $ userName ;
17-
18- protected $ password ;
19-
20- public function __construct (array $ config , Message $ message )
21- {
22- if (array_key_exists ('host ' , $ config )) {
23- $ this ->host = $ config ['host ' ];
24- }
25-
26- if (array_key_exists ('user ' , $ config )) {
27- $ this ->userName = $ config ['user ' ];
28- }
29-
30- if (array_key_exists ('pass ' , $ config )) {
31- $ this ->password = $ config ['pass ' ];
32- }
33-
34- $ this ->message = $ message ;
35- }
36-
37- /**
38- * @return mixed
39- */
40- public function getHost ()
41- {
42- return $ this ->host ;
43- }
44-
45- /**
46- * @return mixed
47- */
48- public function getUserName ()
49- {
50- return $ this ->userName ;
51- }
52-
53- /**
54- * @return mixed
55- */
56- public function getPassword ()
57- {
58- return $ this ->password ;
59- }
60-
6112
62- public function send ($ formFields )
13+ public function send ($ formFields, Message $ message )
6314 {
6415 $ mail = new PHPMailer (true ); // Passing `true` enables exceptions
6516 try {
@@ -68,24 +19,24 @@ public function send($formFields)
6819 $ mail ->isSMTP (); // Set mailer to use SMTP
6920 $ mail ->Host = $ this ->getHost (); // Specify main and backup SMTP servers
7021 $ mail ->SMTPAuth = true ; // Enable SMTP authentication
71- $ mail ->Username = $ this ->getUserName (); // SMTP username
22+ $ mail ->Username = $ this ->getUser (); // SMTP username
7223 $ mail ->Password = $ this ->getPassword (); // SMTP password
7324 $ mail ->SMTPSecure = 'tls ' ; // Enable TLS encryption, `ssl` also accepted
7425 $ mail ->Port = 587 ; // TCP port to connect to
7526
7627 //Recipients
77- if ($ this -> message ->getFromAddress () != '' && $ this -> message ->getFromName () != '' ) {
78- $ mail ->setFrom ($ this -> message ->getFromAddress (), $ this -> message ->getFromName ());
28+ if ($ message ->getFromAddress () != '' && $ message ->getFromName () != '' ) {
29+ $ mail ->setFrom ($ message ->getFromAddress (), $ message ->getFromName ());
7930 }
8031// $mail->addAddress($this->message->getFrom()); // Add a recipient
8132// $mail->addReplyTo('info@example.com', 'Information');
8233
83- if ($ this -> message ->getCcAddress () != '' && $ this -> message ->getBccName () != '' ) {
84- $ mail ->addCC ($ this -> message ->getCcAddress (), $ this -> message ->getBccName ());
34+ if ($ message ->getCcAddress () != '' && $ message ->getBccName () != '' ) {
35+ $ mail ->addCC ($ message ->getCcAddress (), $ message ->getBccName ());
8536 }
8637
87- if ($ this -> message ->getBccAddress () != '' && $ this -> message ->getBccName () != '' ) {
88- $ mail ->addBCC ($ this -> message ->getBccAddress (), $ this -> message ->getBccName ());
38+ if ($ message ->getBccAddress () != '' && $ message ->getBccName () != '' ) {
39+ $ mail ->addBCC ($ message ->getBccAddress (), $ message ->getBccName ());
8940 }
9041
9142 //Attachments
@@ -94,9 +45,9 @@ public function send($formFields)
9445
9546 //Content
9647 $ mail ->isHTML (true ); // Set email format to HTML
97- $ mail ->Subject = $ this -> message ->getSubject ();
98- $ mail ->Body = $ this -> message ->getTemplate ($ formFields );
99- $ mail ->AltBody = $ this -> message ->getAltBody ();
48+ $ mail ->Subject = $ message ->getSubject ();
49+ $ mail ->Body = $ message ->getTemplate ($ formFields );
50+ $ mail ->AltBody = $ message ->getAltBody ();
10051
10152 $ mail ->send ();
10253
0 commit comments