Back to PhocacartEmail class

Method sendQuestionMail

public static
sendQuestionMail
(mixed $data, mixed $url, mixed $tmpl)

Method sendQuestionMail - Source code

public static function sendQuestionMail($data, $url, $tmpl)
{
    $app = Factory::getApplication();
    $db = Factory::getDBO();
    $sitename = $app->get('sitename');
    $paramsC = PhocacartUtils::getComponentParameters();
    $numCharEmail = $paramsC->get('max_char_question_email', 2000);
    $send_email_question = $paramsC->get('send_email_question', 0);
    $send_email_question_others = $paramsC->get('send_email_question_others', '');
    //get all selected users
    $query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE id = ' . (int) $send_email_question;
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    $subject = $sitename . ' - ' . Text::_('COM_PHOCACART_NEW_QUESTION');
    if (isset($data['product']->title) && $data['product']->title != '') {
        $subject .= ', ' . Text::_('COM_PHOCACART_PRODUCT') . ': ' . $data['product']->title;
    }
    if (isset($data['category']->title) && $data['category']->title != '') {
        $subject .= ', ' . Text::_('COM_PHOCACART_CATEGORY') . ': ' . $data['category']->title;
    }
    if (isset($data['name']) && $data['name'] != '') {
        $fromname = $data['name'];
    } else {
        $fromname = 'Unknown';
    }
    if (isset($data['email']) && $data['email'] != '') {
        $mailfrom = $data['email'];
    } else {
        $mailfrom = isset($rows[0]->email) ? $rows[0]->email : '';
    }
    if (isset($data['message']) && $data['message'] != '') {
        $message = $data['message'];
    } else {
        $message = Text::_('COM_PHOCACART_NO_MESSAGE');
    }
    $email = '';
    if (isset($rows[0]->email)) {
        $email = $rows[0]->email;
    }
    $message = str_replace("</p>", "\n", $message);
    $message = strip_tags($message);
    $layoutE = new FileLayout('email_ask_question', null, array('component' => 'com_phocacart'));
    $d = array();
    $d['fromname'] = $fromname;
    $d['name'] = isset($data['name']) ? $data['name'] : '';
    $d['email'] = isset($data['email']) ? $data['email'] : '';
    $d['phone'] = isset($data['phone']) ? $data['phone'] : '';
    $d['subject'] = $subject;
    $d['message'] = $message;
    $d['numcharemail'] = $numCharEmail;
    $d['url'] = $url;
    $d['sitename'] = $sitename;
    $body = $layoutE->render($d);
    $subject = html_entity_decode($subject, ENT_QUOTES);
    $body = html_entity_decode($body, ENT_QUOTES);
    $notify = false;
    // Send email to selected user
    if ($mailfrom != '' && $send_email_question != '' && $email != '') {
        $notify = PhocacartEmail::sendEmail($mailfrom, $fromname, $email, $subject, $body, true, null, null, null, '', '', $mailfrom, $fromname);
    }
    // Send email to others
    $emailOthers = '';
    $bcc = null;
    if (isset($send_email_question_others) && $send_email_question_others != '') {
        $bcc = explode(',', $send_email_question_others);
        if (isset($bcc[0]) && MailHelper::isEmailAddress($bcc[0])) {
            $emailOthers = $bcc[0];
        }
    }
    $notifyOthers = false;
    if ($emailOthers != '' && MailHelper::isEmailAddress($emailOthers)) {
        $notifyOthers = PhocacartEmail::sendEmail($mailfrom, $fromname, $emailOthers, $subject, $body, true, null, $bcc, null, '', '', $mailfrom, $fromname);
    }
    if ($notify || $notifyOthers) {
        return true;
    }
    return false;
}