/**
  * Send mail
  * @params (type, to_email, subject, to_info, list_id)
  */
 public static function send_email($type = 'double-optin', $to_email, $subject, $code = '', $list_id = '', $template_id = 0, $attributes = null)
 {
     $customizations = get_option('wc_sendinblue_settings', array());
     $general_settings = get_option('ws_main_option', array());
     if (!class_exists('Mailin')) {
         require_once 'mailin.php';
     }
     $mailin = new Mailin(WC_Sendinblue::sendinblue_api_url, $general_settings['access_key']);
     // get sender info
     $sender_email = trim(get_bloginfo('admin_email'));
     $sender_name = trim(get_bloginfo('name'));
     // send mail
     $to = array($to_email => '');
     $from = array($sender_email, $sender_name);
     $null_array = array();
     $site_domain = str_replace('https://', '', home_url());
     $site_domain = str_replace('http://', '', $site_domain);
     if ($type == 'woo-campaign') {
         $html_content = isset($customizations['ws_email_campaign_message']) ? $customizations['ws_email_campaign_message'] : '';
         $text_content = strip_tags($html_content);
         //$from = '';
         //$subject = '';
     } else {
         if ($template_id == 0) {
             // default template
             $template_contents = self::get_email_template($type);
             $html_content = $template_contents['html_content'];
             $text_content = $template_contents['text_content'];
         } else {
             $templates = get_option('ws_templates', array());
             $template = $templates[$template_id];
             $html_content = $template['content'];
             $text_content = $template['content'];
             $html_content = str_replace('https://[DOUBLEOPTIN]', '{subscribe_url}', $html_content);
             $html_content = str_replace('http://[DOUBLEOPTIN]', '{subscribe_url}', $html_content);
             $html_content = str_replace('[DOUBLEOPTIN]', '{subscribe_url}', $html_content);
         }
     }
     $html_content = str_replace('{title}', $subject, $html_content);
     $html_content = str_replace('{site_domain}', $site_domain, $html_content);
     $html_content = str_replace('{subscribe_url}', add_query_arg(array('ws_action' => 'subscribe', 'code' => $code, 'li' => $list_id), home_url()), $html_content);
     if ($type == 'notify') {
         // $code is current number of sms credits
         $html_content = str_replace('{present_credit}', $code, $html_content);
     }
     $text_content = str_replace('{site_domain}', home_url(), $text_content);
     if (isset($customizations['ws_smtp_enable']) && $customizations['ws_smtp_enable'] == 'yes') {
         $headers = array("Content-Type" => "text/html; charset=iso-8859-1", "X-Mailin-Tag" => "Woocommerce SendinBlue");
         $data = array("to" => $to, "cc" => array(), "bcc" => array(), "from" => $from, "replyto" => array(), "subject" => $subject, "text" => $text_content, "html" => $html_content, "attachment" => array(), "headers" => $headers, "inline_image" => array());
         $result = $mailin->send_email($data);
         $result = $result['code'] == 'success' ? true : false;
     } else {
         $headers[] = 'Content-Type: text/html; charset=UTF-8';
         $headers[] = "From: {$sender_name} <{$sender_email}>";
         $result = @wp_mail($to_email, $subject, $html_content, $headers);
     }
     return $result;
 }
예제 #2
0
 /**
  * Send mail
  * @params (type, to_email, to_info, list_id)
  */
 function send_email($type, $to_email, $code, $list_id, $template_id = '-1')
 {
     $mailin = new Mailin('https://api.sendinblue.com/v1.0', SIB_Manager::$access_key, SIB_Manager::$secret_key);
     // set subject info
     if ($type == 'confirm') {
         $subject = __('Subscription confirmed', 'sib_lang');
     } elseif ($type == "double-optin") {
         $subject = __('Please confirm subscription', 'sib_lang');
     }
     // get sender info
     if (SIB_Manager::$sender_id == '-1') {
         $sender_email = __('*****@*****.**', 'sib_lang');
         $sender_name = __('SendinBlue', 'sib_lang');
     } else {
         $senders = SIB_Page_Form::get_sender_lists();
         $sender_email = SIB_Manager::$sender_id;
         foreach ($senders as $sender) {
             if ($sender_email == $sender['from_email']) {
                 $sender_name = $sender['from_name'];
                 break;
             }
         }
     }
     if ($sender_email == '') {
         $sender_email = __('*****@*****.**', 'sib_lang');
         $sender_name = __('SendinBlue', 'sib_lang');
     }
     // get template html and text
     $template_contents = self::get_email_template($type);
     $html_content = $template_contents['html_content'];
     $text_content = $template_contents['text_content'];
     if ($type == "confirm" && $template_id != '-1') {
         $response = $mailin->get_campaign($template_id);
         if ($response['code'] == 'success') {
             $html_content = $response['data'][$template_id]['html_content'];
         }
     }
     // send mail
     $to = array($to_email => '');
     $from = array($sender_email, $sender_name);
     $null_array = array();
     $site_domain = str_replace('https://', '', home_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);
     $html_content = str_replace('{unsubscribe_url}', add_query_arg(array('sib_action' => 'unsubscribe', 'code' => $code, 'li' => $list_id), home_url()), $html_content);
     $html_content = str_replace('{subscribe_url}', add_query_arg(array('sib_action' => 'subscribe', 'code' => $code, 'li' => $list_id), home_url()), $html_content);
     $text_content = str_replace('{site_domain}', home_url(), $text_content);
     if (SIB_Manager::$activate_email == 'yes') {
         $headers = array();
         $mailin->send_email($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);
     }
 }
예제 #3
0
<?php

require '../mailin.php';
/*
 * This will initiate the API with the endpoint and your access and secret key.
 *
 */
$mailin = new Mailin('https://api.sendinblue.com/v1.0', 'Your access key', 'Your secret key');
/** Prepare variables for easy use **/
$to = array("*****@*****.**" => "to whom!");
//mandatory
$subject = "My subject";
//mandatory
$from = array("*****@*****.**", "from email!");
//mandatory
$html = "This is the <h1>HTML</h1>";
//mandatory
$text = "This is the text";
$cc = array("*****@*****.**" => "cc whom!");
$bcc = array("*****@*****.**" => "bcc whom!");
$replyto = array("*****@*****.**", "reply to!");
$attachment = array();
//provide the absolute url of the attachment/s
$headers = array("Content-Type" => "text/html; charset=iso-8859-1", "X-Ewiufkdsjfhn" => "hello", "X-Custom" => "Custom");
var_dump($mailin->send_email($to, $subject, $from, $html, $text, $cc, $bcc, $replyto, $attachment, $headers));
 /** ajax module for send test email */
 public static function ajax_send_email()
 {
     $to = array($_POST['email'] => '');
     $subject = __('[SendinBlue SMTP] test email', 'sib_lang');
     $fromname = __('SendinBlue', 'sib_lang');
     $from_email = __('*****@*****.**', 'sib_lang');
     $from = array($from_email, $fromname);
     $null_array = array();
     $email_templates = SIB_Manager::get_email_template('test');
     $text = $email_templates['text_content'];
     $html = $email_templates['html_content'];
     $html = str_replace('{title}', $subject, $html);
     $mailin = new Mailin(SIB_Manager::sendinblue_api_url, SIB_Manager::$access_key);
     $headers = array("Content-Type" => "text/html;charset=iso-8859-1", "X-Mailin-tag" => 'Wordpress Mailin Test');
     $data = array("to" => $to, "subject" => $subject, "from" => $from, "text" => $email_templates['text_content'], "html" => $html, "headers" => $headers);
     $result = $mailin->send_email($data);
     echo 'success';
     die;
 }
예제 #5
0
<?php

require 'Mailin.php';
/*
 * This will initiate the API with the endpoint and your access key.
 *
 */
$mailin = new Mailin('https://api.sendinblue.com/v2.0', 'Your access key');
/*
 * This will send a transactional email
 *
 */
/** Prepare variables for easy use **/
$data = array("to" => array("*****@*****.**" => "to whom!"), "cc" => array("*****@*****.**" => "cc whom!"), "bcc" => array("*****@*****.**" => "bcc whom!"), "from" => array("*****@*****.**", "from email!"), "replyto" => array("*****@*****.**", "reply to!"), "subject" => "My subject", "text" => "This is the text", "html" => "This is the <h1>HTML</h1><br/>\n\t\t\t\t\t   This is inline image 1.<br/>\n\t\t\t\t\t   <img src=\"{myinlineimage1.png}\" alt=\"image1\" border=\"0\"><br/>\n\t\t\t\t\t   Some text<br/>\n\t\t\t\t\t   This is inline image 2.<br/>\n\t\t\t\t\t   <img src=\"{myinlineimage2.jpg}\" alt=\"image2\" border=\"0\"><br/>\n\t\t\t\t\t   Some more text<br/>\n\t\t\t\t\t   Re-used inline image 1.<br/>\n\t\t\t\t\t   <img src=\"{myinlineimage1.png}\" alt=\"image3\" border=\"0\">", "attachment" => array(), "headers" => array("Content-Type" => "text/html; charset=iso-8859-1", "X-param1" => "value1", "X-param2" => "value2", "X-Mailin-custom" => "my custom value", "X-Mailin-IP" => "102.102.1.2", "X-Mailin-Tag" => "My tag"), "inline_image" => array('myinlineimage1.png' => "your_png_files_base64_encoded_chunk_data", 'myinlineimage2.jpg' => "your_jpg_files_base64_encoded_chunk_data"));
var_dump($mailin->send_email($data));
 /**
  * Send mail
  * @params (type, to_email, to_info, list_id)
  */
 function send_email($type, $to_email, $code, $list_id, $template_id = '-1', $attributes = null)
 {
     $mailin = new Mailin(SIB_Manager::sendinblue_api_url, SIB_Manager::$access_key);
     // set subject info
     if ($type == 'confirm') {
         $subject = __('Subscription confirmed', 'sib_lang');
     } elseif ($type == "double-optin") {
         $subject = __('Please confirm subscription', 'sib_lang');
     }
     // get sender info
     if (self::$account_email != '') {
         $sender_name = trim(self::$account_user_name);
         $sender_email = trim(self::$account_email);
     } else {
         $sender_email = trim(get_bloginfo('admin_email'));
         $sender_name = trim(get_bloginfo('name'));
     }
     if ($sender_email == '') {
         $sender_email = __('*****@*****.**', 'sib_lang');
         $sender_name = __('SendinBlue', 'sib_lang');
     }
     $template_contents = self::get_email_template($type);
     $html_content = $template_contents['html_content'];
     $text_content = $template_contents['text_content'];
     $transactional_tags = 'Wordpress Mailin';
     // get template html and text
     if (intval($template_id) > 0) {
         $data = array('id' => $template_id);
         $response = $mailin->get_campaign_v2($data);
         if ($response['code'] == 'success') {
             $html_content = $response['data'][0]['html_content'];
             if (trim($response['data'][0]['subject']) != '') {
                 $subject = trim($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'];
             }
             $transactional_tags = $response['data'][0]['campaign_name'];
         }
     }
     // send mail
     $to = array($to_email => '');
     $from = array($sender_email, $sender_name);
     $null_array = array();
     $site_domain = str_replace('https://', '', home_url());
     $site_domain = str_replace('http://', '', $site_domain);
     $html_content = str_replace('{title}', $subject, $html_content);
     $html_content = str_replace('https://[DOUBLEOPTIN]', '{subscribe_url}', $html_content);
     $html_content = str_replace('http://[DOUBLEOPTIN]', '{subscribe_url}', $html_content);
     $html_content = str_replace('[DOUBLEOPTIN]', '{subscribe_url}', $html_content);
     $html_content = str_replace('{site_domain}', $site_domain, $html_content);
     $html_content = str_replace('{unsubscribe_url}', add_query_arg(array('sib_action' => 'unsubscribe', 'code' => $code, 'li' => $list_id), home_url()), $html_content);
     $html_content = str_replace('{subscribe_url}', add_query_arg(array('sib_action' => 'subscribe', 'code' => $code, 'li' => $list_id), home_url()), $html_content);
     $text_content = str_replace('{site_domain}', home_url(), $text_content);
     if (SIB_Manager::$activate_email == 'yes') {
         if (intval($template_id) > 0 && is_array($attributes) && $type == "confirm") {
             $attrs = array_merge($attributes, array('EMAIL' => $to_email));
             $data = array("id" => intval($template_id), "to" => $to_email, "cc" => "", "bcc" => "", "attr" => $attrs, "attachment_url" => "", "attachment" => array(), "headers" => array("Content-Type" => "text/html;charset=iso-8859-1", "X-Mailin-tag" => $transactional_tags));
             $mailin->send_transactional_template($data);
         } else {
             $headers = array("Content-Type" => "text/html;charset=iso-8859-1", "X-Mailin-tag" => $transactional_tags);
             $data = array("to" => $to, "cc" => array(), "bcc" => array(), "from" => $from, "replyto" => array(), "subject" => $subject, "text" => $text_content, "html" => $html_content, "attachment" => array(), "headers" => $headers, "inline_image" => array());
             $mailin->send_email($data);
         }
     } else {
         $headers[] = 'Content-Type: text/html; charset=UTF-8';
         $headers[] = "From: {$sender_name} <{$sender_email}>";
         @wp_mail($to_email, $subject, $html_content, $headers);
     }
 }
예제 #7
0
 /** ajax module for send test email */
 function ajax_send_email()
 {
     $to = array($_POST['email'] => '');
     $subject = __('[SendinBlue SMTP] test email', 'sib_lang');
     $fromname = __('SendinBlue', 'sib_lang');
     $from_email = __('*****@*****.**', 'sib_lang');
     $from = array($from_email, $fromname);
     $null_array = array();
     $email_templates = SIB_Manager::get_email_template('test');
     $text = $email_templates['text_content'];
     $html = $email_templates['html_content'];
     $html = str_replace('{title}', $subject, $html);
     $mailin = new Mailin('https://api.sendinblue.com/v1.0', SIB_Manager::$access_key, SIB_Manager::$secret_key);
     $headers = array();
     $mailin->send_email($to, $subject, $from, $html, $text, $null_array, $null_array, $from, $null_array, $headers);
     echo 'success';
     die;
 }