Esempio n. 1
0
function send_email($_to = '', $_subject = '', $_body = '', $_cc = array(), $_bcc = array(), $_from = '*****@*****.**', $_fromName = 'Terroni')
{
    require_once 'class/PHPMailer/class.phpmailer.php';
    $m_return = true;
    if (!GlobalFunctions::CompareStrings(WP_ENV, 'dev')) {
        try {
            $email = new PHPMailer();
            $email->From = $_from;
            $email->FromName = $_fromName;
            $email->addAddress($_to);
            $email->Subject = $_subject;
            $email->Body = $_body;
            $email->isHTML(true);
            // add CC
            foreach ($_cc as $item) {
                $email->addCC($item);
            }
            // add BCC
            foreach ($_bcc as $item) {
                $email->addBCC($item);
            }
            if (!$email->send()) {
                error_log(sprintf('Email: Could not send email for %s to %s', $_subject, $_to));
                $m_return = false;
            }
            // if
        } catch (Exception $e) {
            error_log(sprintf('Email: Error trying to send email for %s to %s. Msg: %s', $_subject, $_to, $e->getMessage()));
            $m_return = false;
        }
        // try/catch
    } else {
        // print the body
        echo $_body;
    }
    return $m_return;
}