Rev 182 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
declare(strict_types=1);
namespace LeadersLinked\Library;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Model\EmailTemplate;
use LeadersLinked\Model\Email;
use LeadersLinked\Mapper\EmailMapper;
class QueueEmail
{
/**
*
* @var AdapterInterface
*/
private $adapter;
/**
*
* @param AdapterInterface $adapter
*/
public function __construct($adapter)
{
$this->adapter = $adapter;
}
/**
*
* @param EmailTemplate $emailTemplate
* @param array $arrayCont
* @param string $to_address
* @param string $to_name
* @return boolean
*/
public function processEmailTemplate($emailTemplate, $arrayCont, $to_address, $to_name)
{
$subject = trim(stripslashes($emailTemplate->subject));
$message = trim(stripslashes($emailTemplate->content));
foreach($arrayCont as $key => $val)
{
if('link' == $key) {
$from_hostname = empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST'];
$from_hostname = str_replace('https://', '', $from_hostname);
$to_hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
if(empty($to_hostname)) {
$to_hostname = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
}
$to_hostname = str_replace('https://', '', $to_hostname);
if($from_hostname && $to_hostname) {
$val = str_replace($from_hostname, $to_hostname, $val);
}
}
$message = str_replace('[' . $key .']', $val, $message);
$subject = str_replace('[' . $key .']', $val, $subject);
}
$email = new Email();
$email->content = json_encode([
'to_address' => $to_address,
'to_name' => $to_name,
'cc' => [],
'bcc' => [],
'subject' => $subject,
'message' => $message,
]);
$email->status = Email::STATUS_PENDING;
$email->tried = 0;
$emailMapper = EmailMapper::getInstance($this->adapter);
return $emailMapper->insert($email);
}
}