| @@ -1,11 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Util; |
| 4 | 4 | |
| 5 | +if (!defined('ABSPATH')) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 6 | 10 | |
| 7 | - | |
| 8 | 11 | /** |
| 9 | 12 | * Class handling plugin activation. |
| 10 | 13 | * |
| 11 | 14 | * @since 1.0.0 |
| @@ -11,32 +14,47 @@ | ||
| 11 | 14 | * @since 1.0.0 |
| 12 | 15 | */ |
| 13 | 16 | final class MailConfig |
| 14 | 17 | { |
| 15 | - public function sendMail() | |
| 16 | - { | |
| 17 | - add_action('phpmailer_init', [$this, 'mailConfig'], 10, 1); | |
| 18 | - } | |
| 19 | - function mailConfig($phpmailer) | |
| 20 | - { | |
| 21 | - $integrationHandler = new IntegrationHandler(0); | |
| 22 | - $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp', 1); | |
| 23 | - if (!isset($formIntegrations->errors['result_empty'])) { | |
| 24 | - if ($formIntegrations[0]->status == 1) { | |
| 25 | - $integration_details = json_decode($formIntegrations[0]->integration_details); | |
| 26 | - $phpmailer->Mailer = 'smtp'; | |
| 27 | - $phpmailer->Host = $integration_details->smtp_host; | |
| 28 | - $phpmailer->SMTPAuth = true; | |
| 29 | - if(!empty($integration_details->re_email_address)){ | |
| 30 | - $phpmailer->addReplyTo($integration_details->re_email_address,'reply-to'); | |
| 31 | - } | |
| 32 | - $phpmailer->Port = $integration_details->port; | |
| 33 | - $phpmailer->Username = $integration_details->smtp_user_name; | |
| 34 | - $phpmailer->Password = $integration_details->smtp_password; | |
| 35 | - $phpmailer->SMTPSecure = $integration_details->encryption; | |
| 36 | - $phpmailer->SMTP_DEBUG = 1; | |
| 37 | - $phpmailer->From = $integration_details->form_email_address; | |
| 38 | - $phpmailer->FromName = $integration_details->form_name; | |
| 39 | - } | |
| 18 | + private $config; | |
| 19 | + | |
| 20 | + public function sendMail($config = []) | |
| 21 | + { | |
| 22 | + $this->config = $config; | |
| 23 | + add_action('phpmailer_init', [$this, 'mailConfig'], 10, 1); | |
| 24 | + } | |
| 25 | + | |
| 26 | + public function mailConfig($phpmailer) | |
| 27 | + { | |
| 28 | + $integrationHandler = new IntegrationHandler(0); | |
| 29 | + $formIntegrations = $integrationHandler->getAllIntegration('mail', 'smtp', 1); | |
| 30 | + if (!isset($formIntegrations->errors['result_empty'])) { | |
| 31 | + $integrationRow = Utilities::firstRow($formIntegrations); | |
| 32 | + if ($integrationRow && 1 === (int) $integrationRow->status) { | |
| 33 | + $integration_details = Utilities::jsonObj($integrationRow->integration_details ?? ''); | |
| 34 | + $phpmailer->Mailer = 'smtp'; | |
| 35 | + $phpmailer->Host = $integration_details->smtp_host ?? ''; | |
| 36 | + $phpmailer->SMTPAuth = true; | |
| 37 | + if (!empty($integration_details->re_email_address)) { | |
| 38 | + $phpmailer->addReplyTo($integration_details->re_email_address, 'reply-to'); | |
| 40 | 39 | } |
| 40 | + $phpmailer->Port = $integration_details->port ?? ''; | |
| 41 | + $phpmailer->Username = $integration_details->smtp_user_name ?? ''; | |
| 42 | + $phpmailer->Password = $integration_details->smtp_password ?? ''; | |
| 43 | + $phpmailer->SMTPSecure = $integration_details->encryption ?? ''; | |
| 44 | + // $phpmailer->SMTPDebug = 1; | |
| 45 | + // $phpmailer->Debugoutput = 'error_log'; | |
| 46 | + $phpmailer->From = $integration_details->form_email_address ?? ''; | |
| 47 | + $phpmailer->Sender = $integration_details->form_email_address ?? ''; | |
| 48 | + if (isset($this->config['from_email']) && !empty($this->config['from_email'])) { | |
| 49 | + $phpmailer->From = $this->config['from_email']; | |
| 50 | + $phpmailer->Sender = $this->config['from_email']; | |
| 51 | + } | |
| 52 | + $from_name = $integration_details->form_name ?? ''; | |
| 53 | + if (isset($this->config['from_name']) && !empty($this->config['from_name'])) { | |
| 54 | + $from_name = $this->config['from_name']; | |
| 55 | + } | |
| 56 | + $phpmailer->FromName = $from_name; | |
| 57 | + } | |
| 41 | 58 | } |
| 59 | + } | |
| 42 | 60 | } |