/var/www/html_fr/wp-content/plugins/fluent-smtp/app/Services/Mailer/Providers/Smtp/Handler.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php

namespace FluentMail\App\Services\Mailer\Providers\Smtp;

use 
FluentMail\Includes\Support\Arr;
use 
FluentMail\Includes\Core\Application;
use 
FluentMail\App\Services\Mailer\BaseHandler;
use 
FluentMail\App\Services\Mailer\Providers\Smtp\ValidatorTrait;

class 
Handler extends BaseHandler
{
    use 
ValidatorTrait;

    public function 
send()
    {
        if (
$this->preSend()) {
            if (
$this->getSetting('auto_tls') == 'no') {
                
$this->phpMailer->SMTPAutoTLS false;
            }
            return 
$this->postSend();
        }

        return 
$this->handleResponse(new \WP_Error(422__('Something went wrong!''fluent-smtp'), []));
    }

    protected function 
postSend()
    {
        try {
            
$this->phpMailer->isSMTP();
            
$this->phpMailer->Host $this->getSetting('host');
            
$this->phpMailer->Port $this->getSetting('port');

            if (
$this->getSetting('auth') == 'yes') {
                
$this->phpMailer->SMTPAuth true;
                
$this->phpMailer->Username $this->getSetting('username');
                
$this->phpMailer->Password $this->getSetting('password');
            }

            if ((
$encryption $this->getSetting('encryption')) != 'none') {
                
$this->phpMailer->SMTPSecure $encryption;
            }

            
$fromEmail $this->phpMailer->From;

            if (
$this->isForcedEmail() && !fluentMailIsListedSenderEmail($fromEmail)) {
                
$fromEmail $this->getSetting('sender_email');
            }

            if (isset(
$this->phpMailer->FromName)) {
                
$fromName $this->phpMailer->FromName;

                if (
                    
$this->getSetting('force_from_name') == 'yes' &&
                    
$customFrom $this->getSetting('sender_name')
                ) {
                    
$fromName $customFrom;
                }

                
$this->phpMailer->setFrom($fromEmail$fromName);
            } else {
                
$this->phpMailer->setFrom($fromEmail);
            }

            foreach (
$this->getParam('to') as $to) {
                if (isset(
$to['name'])) {
                    
$this->phpMailer->addAddress($to['email'], $to['name']);
                } else {
                    
$this->phpMailer->addAddress($to['email']);
                }
            }

            foreach (
$this->getParam('headers.reply-to') as $replyTo) {
                if (isset(
$replyTo['name'])) {
                    
$this->phpMailer->addReplyTo($replyTo['email'], $replyTo['name']);
                } else {
                    
$this->phpMailer->addReplyTo($replyTo['email']);
                }
            }

            foreach (
$this->getParam('headers.cc') as $cc) {
                if (isset(
$cc['name'])) {
                    
$this->phpMailer->addCC($cc['email'], $cc['name']);
                } else {
                    
$this->phpMailer->addCC($cc['email']);
                }
            }

            foreach (
$this->getParam('headers.bcc') as $bcc) {
                if (isset(
$bcc['name'])) {
                    
$this->phpMailer->addBCC($bcc['email'], $bcc['name']);
                } else {
                    
$this->phpMailer->addBCC($bcc['email']);
                }
            }

            if (
$attachments $this->getParam('attachments')) {
                foreach (
$attachments as $attachment) {
                    
$this->phpMailer->addAttachment($attachment[0], $attachment[7]);
                }
            }

            if (
$this->getParam('headers.content-type') == 'text/html' || $this->getParam('headers.content-type') == 'multipart/alternative') {
                
$this->phpMailer->isHTML(true);
            }

            
$this->phpMailer->Subject $this->getSubject();

            
$this->phpMailer->Body $this->getParam('message');

            if (
$this->getParam('headers.content-type') == 'multipart/alternative') {
                
$this->phpMailer->AltBody $this->getParam('alt_body');
                
$this->phpMailer->ContentType 'multipart/alternative';
            }

            
$this->phpMailer->send();

            
$returnResponse = [
                
'response' => 'OK'
            
];

        } catch (
\Exception $e) {
            
$returnResponse = new \WP_Error(422$e->getMessage(), []);
        }

        
$this->response $returnResponse;

        return 
$this->handleResponse($this->response);
    }

    public function 
setSettings($settings)
    {
        if (
Arr::get($settings'key_store') == 'wp_config') {
            
$settings['username'] = defined('FLUENTMAIL_SMTP_USERNAME') ? FLUENTMAIL_SMTP_USERNAME '';
            
$settings['password'] = defined('FLUENTMAIL_SMTP_PASSWORD') ? FLUENTMAIL_SMTP_PASSWORD '';
        }

        
$this->settings $settings;

        return 
$this;
    }
}