HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/jhtaxatie.creativefellows.nl/classes/CampaignMonitorReader.php
<?php

use CS_REST_Transactional_ClassicEmail;


final class CampaignMonitorReader
{

    public function __construct(){
		$this->cm_auth 		= ['api_key' => 'jSaSN4T1u8Unvb1BI290cTPND3yeIljcBHgDgF8XruDW9waKGi6RTcXTLY7gXeOzH+rHh+vH/B2AfqSu/mmO72lob7rAbfz23KlX+YC55vDKHJB5JwSpEgtRJwXHCNWHutcYbxi5cNGMYGPjk+zoiQ=='];
		$this->cm_client_id = '1d6df94c8dc60aad503918bd38b3378a';
	}
	
	public function set($data = [])
	{
		$this->from 		= $data["from"];
		$this->subject 		= $data["subject"];
		$this->to 			= $data["to"];
		$this->html 		= $data["html"];
		$this->cm_label		= $data["cm_label"];
		$this->attachment	= $data["attachment_base64"];
		$this->pdf_name		= $data["pdf_name"];
		
		if(isset($data["bcc"])) $this->bcc = $data["bcc"];
		
		
	}
	
	public function send()
	{
		
		$mail = new CS_REST_Transactional_ClassicEmail($this->cm_auth, $this->cm_client_id);
		
		$message = [
		  "From" => $this->from,
		  "Subject" => $this->subject,
		  "To" => $this->to,
		  "HTML" => $this->html,
		];

		// check for BCC
		if(isset($this->bcc)) $message["BCC"] = $this->bcc;

		// attachment present?  
		if($this->attachment && $this->pdf_name){
			$message["Attachments"] = [[
		      "Name" => $this->pdf_name,
		      "Type" => "application/pdf",
		      "Content" => base64_encode($this->attachment)
			]];
		}
					
		$group_name = 'Invite'; # optional but great for reporting, should not be unique per message
		$consent_to_track = 'yes'; # Valid: 'yes', 'no', 'unchanged'

		$result = $mail->send($message, $this->cm_label,$consent_to_track);
				
		return $result->http_status_code;
		
		
	}
	
	
	public function replaceText($template_location, $replacements)
	{

		$text_email = file_get_contents($template_location);
		$keys 	= array_keys($replacements);
		$values = array_values($replacements);

		return preg_replace($keys,$values,$text_email);
	
	}

}