You are here

public static function SendinblueManager::sendEmail in SendinBlue 7

Same name and namespace in other branches
  1. 7.2 includes/sendinblue.manage.inc \SendinblueManager::sendEmail()

Send mail.

Parameters

string $type: A type of email.

string $to_email: A recipe address.

string $code: A activate code.

int $list_id: A list identification.

string $sender_id: A sender identification.

string $template_id: A template identification.

2 calls to SendinblueManager::sendEmail()
sendinblue_send_email_form_submit in includes/sendinblue_home.admin.inc
Submit Handler of Form to send email of Home page.
sendinblue_signup_subscribe_form_validate in ./sendinblue.module
Validate handler to add users to lists on subscription form submission.

File

includes/sendinblue.manage.inc, line 280
Manage class file.

Class

SendinblueManager
Basic manager of module.

Code

public static function sendEmail($type, $to_email, $code, $list_id, $sender_id = '-1', $template_id = '-1') {
  $access_key = variable_get(self::ACCESS_KEY, '');
  $mailin = new SendinblueMailin(self::API_URL, $access_key);
  $account_email = variable_get(self::ACCOUNT_EMAIL, '');
  $account_username = variable_get(self::ACCOUNT_USERNAME, '');

  // Set subject info.
  if ($type == 'confirm') {
    $subject = t('Subscription confirmed');
  }
  elseif ($type == "double-optin") {
    $subject = t('Please confirm subscription');
  }
  elseif ($type == 'test') {
    $subject = t('[SendinBlue SMTP] test email');
  }
  $sender_email = $account_email;
  $sender_name = $account_username;
  if ($sender_email == '') {
    $sender_email = t('no-reply@sendinblue.com');
    $sender_name = t('SendinBlue');
  }

  // Get template html and text.
  $template_contents = self::getEmailTemplate($type);
  $html_content = $template_contents['html_content'];
  $text_content = $template_contents['text_content'];
  if ($type == "confirm" && $template_id != '-1') {
    $response = $mailin
      ->getCampaign($template_id);
    if ($response['code'] == 'success') {
      $html_content = $response['data'][0]['html_content'];
      $subject = $response['data'][0]['subject'];
      if ($response['data'][0]['from_name'] != '[DEFAULT_FROM_NAME]' && $response['data'][0]['from_email'] != '[DEFAULT_FROM_EMAIL]' && $response['data'][0]['from_email'] != '') {
        $sender_name = $response['data'][0]['from_name'];
        $sender_email = $response['data'][0]['from_email'];
      }
    }
  }

  // Send mail.
  $to = array(
    $to_email => '',
  );
  $from = array(
    $sender_email,
    $sender_name,
  );
  $null_array = array();
  $base_url = self::getBaseUrl();
  $site_domain = str_replace('https://', '', $base_url);
  $site_domain = str_replace('http://', '', $site_domain);
  $html_content = str_replace('{title}', $subject, $html_content);
  $html_content = str_replace('{site_domain}', $site_domain, $html_content);
  $text_content = str_replace('{site_domain}', self::getBaseUrl(), $text_content);
  $activate_email = variable_get('sendinblue_on', 0);
  if ($activate_email == '1') {
    $headers = array();
    $mailin
      ->sendEmail($to, $subject, $from, $html_content, $text_content, $null_array, $null_array, $from, $null_array, $headers);
  }
  else {
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: ' . $sender_name . ' <' . $sender_email . '>' . "\r\n";
    mail($to_email, $subject, $html_content, $headers);
  }
}