I'm trying to modify an existing PHP email function on the Yeti CRM platform. Right now the function sendFromTemplate($params) takes the collected form variables(stored in $params) and sends it to another function that writes it to a database table to be queued and sent every five minutes. I am trying to use PHPMailer or native PHP to send the email directly but I keep getting errors.
In the code I commented out the addMail function that does the databse queuing and instead set $params = $mailer->send(). I get the error: " PHP Fatal error: Uncaught Error: Call to a member function send() on null.
Other code I've tried and the error
$params = $mailer->send($params); PHP Fatal error: Uncaught Error: Call to a member function send() on null
$params->mailer->send(); PHP Fatal error: Uncaught Error: Call to a member function send() on null
return ['result' => $params->send(), 'error' => implode(PHP_EOL, $params->error)]; PHP Fatal error: Uncaught Error: Call to a member function send() on array
Here is the function that I am modifying.
public static function sendFromTemplate($params)
{
Log::warning('Send mail from template', 'Mailer');
//error_log('Testing - sendFromTemplate');
if (empty($params['template'])) {
Log::warning('No templete', 'Mailer');
return false;
}
$recordModel = false;
if (empty($params['recordModel'])) {
$moduleName = $params['moduleName'] ?? null;
if (isset($params['recordId'])) {
$recordModel = \Vtiger_Record_Model::getInstanceById($params['recordId'], $moduleName);
}
} else {
$recordModel = $params['recordModel'];
}
//error_log('Template Name: ' . $params['template']);
$template = Mail::getTemplete($params['template']);
//error_log('Testing - template: ' . print_r($template, false));
if (!$template) {
Log::warning('No mail templete', 'Mailer');
return false;
}
//error_log('have a template and all');
$textParser = $recordModel ? TextParser::getInstanceByModel($recordModel) : TextParser::getInstance($params['moduleName'] ?? '');
if (!empty($params['language'])) {
$textParser->setLanguage($params['language']);
}
if (!empty($params['sourceRecord'])) {
$textParser->setSourceRecord($params['sourceRecord'], $params['sourceModule']);
}
$textParser->setParams(array_diff_key($params, array_flip(['subject', 'content', 'attachments', 'recordModel'])));
$params['subject'] = $textParser->setContent($template['subject'])->parse()->getContent();
$params['content'] = $textParser->setContent($template['content'])->parse()->getContent();
//Added to allow for something extra from customer service.
$params['content'] = str_replace("$(zcoMessage)", $params['message'], $params['content']);
unset($textParser);
if (empty($params['smtp_id']) && isset($template['smtp_id'])) {
$params['smtp_id'] = $template['smtp_id'];
}
if (isset($template['attachments'])) {
$params['attachments'] = array_merge(empty($params['attachments']) ? [] : $params['attachments'], $template['attachments']);
}
if (!empty($template['email_template_priority'])) {
$params['priority'] = $template['email_template_priority'];
}
$params = $mailer->send();
return true;
//return static::addMail(array_intersect_key($params, array_flip(static::$quoteColumn)));
}
I have no idea what I am doing wrong at this point so any input would be appreciated. I just need to send an email.