jjzjj

php - Codeigniter 电子邮件 - 添加 BCC

coder 2024-05-05 原文

我是新手,所以请多多包涵。 我正在尝试将 BCC 收件人添加到 codeigniter 应用程序的 email.php 配置文件之一。原件是由一名离开我们公司的员工创建的,我正在努力将密件抄送收件人添加到代码中。 我搜索了 stackoverflow 并尝试了无穷无尽的变化,但我没有任何运气。我想要做的就是定义一个密件抄送电子邮件收件人。 我真的非常感谢任何人的帮助:)

这是我认为相关的当前代码的一部分:

 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package     CodeIgniter
 * @author      ExpressionEngine Dev Team
 * @copyright   Copyright (c) 2008 - 2011, EllisLab, Inc.
 * @license     http://codeigniter.com/user_guide/license.html
 * @link        http://codeigniter.com
 * @since       Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter Email Class
 *
 * Permits email to be sent using Mail, Sendmail, or SMTP.
 *
 * @package     CodeIgniter
 * @subpackage  Libraries
 * @category    Libraries
 * @author      ExpressionEngine Dev Team
 * @link        http://codeigniter.com/user_guide/libraries/email.html
 */
class CI_Email {

var $useragent      = "CodeIgniter";
var $mailpath       = "/usr/sbin/sendmail"; // Sendmail path
var $protocol       = "mail";   // mail/sendmail/smtp
var $smtp_host      = "";       // SMTP Server.  Example: mail.earthlink.net
var $smtp_user      = "";       // SMTP Username
var $smtp_pass      = "";       // SMTP Password
var $smtp_port      = "25";     // SMTP Port
var $smtp_timeout   = 5;        // SMTP Timeout in seconds
var $smtp_crypto    = "";       // SMTP Encryption. Can be null, tls or ssl.
var $wordwrap       = TRUE;     // TRUE/FALSE  Turns word-wrap on/off
var $wrapchars      = "76";     // Number of characters to wrap at.
var $mailtype       = "text";   // text/html  Defines email formatting
var $charset        = "utf-8";  // Default char set: iso-8859-1 or us-ascii
var $multipart      = "mixed";  // "mixed" (in the body) or "related" (separate)
var $alt_message    = '';       // Alternative message for HTML emails
var $validate       = FALSE;    // TRUE/FALSE.  Enables email validation
var $priority       = "3";      // Default priority (1 - 5)
var $newline        = "\n";     // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
var $crlf           = "\n";     // The RFC 2045 compliant CRLF for quoted-printable is "\r\n".  Apparently some servers,
                                // even on the receiving end think they need to muck with CRLFs, so using "\n", while
                                // distasteful, is the only thing that seems to work for all environments.
var $send_multipart = TRUE;     // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override.  Set to FALSE for Yahoo.
var $bcc_batch_mode = FALSE;    // TRUE/FALSE  Turns on/off Bcc batch feature
var $bcc_batch_size = 200;      // If bcc_batch_mode = TRUE, sets max number of Bccs in each batch
var $_safe_mode     = FALSE;
var $_subject       = "";
var $_body          = "";
var $_finalbody     = "";
var $_alt_boundary  = "";
var $_atc_boundary  = "";
var $_header_str    = "";
var $_smtp_connect  = "";
var $_encoding      = "8bit";
var $_IP            = FALSE;
var $_smtp_auth     = FALSE;
var $_replyto_flag  = FALSE;
var $_debug_msg     = array();
var $_recipients    = array();
var $_cc_array      = array();
var $_bcc_array     = array();
var $_headers       = array();
var $_attach_name   = array();
var $_attach_type   = array();
var $_attach_disp   = array();
var $_protocols     = array('mail', 'sendmail', 'smtp');
var $_base_charsets = array('us-ascii', 'iso-2022-');   // 7-bit charsets (excluding language suffix)
var $_bit_depths    = array('7bit', '8bit');
var $_priorities    = array('1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)');


/**
 * Constructor - Sets Email Preferences
 *
 * The constructor can be passed an array of config values
 */
public function __construct($config = array())
{
    if (count($config) > 0)
    {
        $this->initialize($config);
    }
    else
    {
        $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
        $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE;
    }

    log_message('debug', "Email Class Initialized");
}

// --------------------------------------------------------------------

/**
 * Initialize preferences
 *
 * @access  public
 * @param   array
 * @return  void
 */
public function initialize($config = array())
{
    foreach ($config as $key => $val)
    {
        if (isset($this->$key))
        {
            $method = 'set_'.$key;

            if (method_exists($this, $method))
            {
                $this->$method($val);
            }
            else
            {
                $this->$key = $val;
            }
        }
    }
    $this->clear();

    $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE;
    $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE;

    return $this;
}

// --------------------------------------------------------------------

/**
 * Initialize the Email Data
 *
 * @access  public
 * @return  void
 */
public function clear($clear_attachments = FALSE)
{
    $this->_subject     = "";
    $this->_body        = "";
    $this->_finalbody   = "";
    $this->_header_str  = "";
    $this->_replyto_flag = FALSE;
    $this->_recipients  = array();
    $this->_cc_array    = array();
    $this->_bcc_array   = array();
    $this->_headers     = array();
    $this->_debug_msg   = array();

    $this->_set_header('User-Agent', $this->useragent);
    $this->_set_header('Date', $this->_set_date());

    if ($clear_attachments !== FALSE)
    {
        $this->_attach_name = array();
        $this->_attach_type = array();
        $this->_attach_disp = array();
    }

    return $this;
}

// --------------------------------------------------------------------

/**
 * Set FROM
 *
 * @access  public
 * @param   string
 * @param   string
 * @return  void
 */
public function from($from, $name = '')
{
    if (preg_match( '/\<(.*)\>/', $from, $match))
    {
        $from = $match['1'];
    }

    if ($this->validate)
    {
        $this->validate_email($this->_str_to_array($from));
    }

    // prepare the display name
    if ($name != '')
    {
        // only use Q encoding if there are characters that would require it
        if ( ! preg_match('/[\200-\377]/', $name))
        {
            // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes
            $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"';
        }
        else
        {
            $name = $this->_prep_q_encoding($name, TRUE);
        }
    }

    $this->_set_header('From', $name.' <'.$from.'>');
    $this->_set_header('Return-Path', '<'.$from.'>');

    return $this;
}

// --------------------------------------------------------------------

/**
 * Set Reply-to
 *
 * @access  public
 * @param   string
 * @param   string
 * @return  void
 */
public function reply_to($replyto, $name = '')
{
    if (preg_match( '/\<(.*)\>/', $replyto, $match))
    {
        $replyto = $match['1'];
    }

    if ($this->validate)
    {
        $this->validate_email($this->_str_to_array($replyto));
    }

    if ($name == '')
    {
        $name = $replyto;
    }

    if (strncmp($name, '"', 1) != 0)
    {
        $name = '"'.$name.'"';
    }

    $this->_set_header('Reply-To', $name.' <'.$replyto.'>');
    $this->_replyto_flag = TRUE;

    return $this;
}

// --------------------------------------------------------------------

/**
 * Set Recipients
 *
 * @access  public
 * @param   string
 * @return  void
 */
public function to($to)
{
    $to = $this->_str_to_array($to);
    $to = $this->clean_email($to);

    if ($this->validate)
    {
        $this->validate_email($to);
    }

    if ($this->_get_protocol() != 'mail')
    {
        $this->_set_header('To', implode(", ", $to));
    }

    switch ($this->_get_protocol())
    {
        case 'smtp'     :
            $this->_recipients = $to;
        break;
        case 'sendmail' :
        case 'mail'     :
            $this->_recipients = implode(", ", $to);
        break;
    }

    return $this;
}

// --------------------------------------------------------------------

/**
 * Set CC
 *
 * @access  public
 * @param   string
 * @return  void
 */
public function cc($cc)
{
    $cc = $this->_str_to_array($cc);
    $cc = $this->clean_email($cc);

    if ($this->validate)
    {
        $this->validate_email($cc);
    }

    $this->_set_header('Cc', implode(", ", $cc));

    if ($this->_get_protocol() == "smtp")
    {
        $this->_cc_array = $cc;
    }

    return $this;
}

// --------------------------------------------------------------------

/**
 * Set BCC
 *
 * @access  public
 * @param   string
 * @param   string
 * @return  void
 */
public function bcc($bcc, $limit = '')
{
    if ($limit != '' && is_numeric($limit))
    {
        $this->bcc_batch_mode = TRUE;
        $this->bcc_batch_size = $limit;
    }

    $bcc = $this->_str_to_array($bcc);
    $bcc = $this->clean_email($bcc);

    if ($this->validate)
    {
        $this->validate_email($bcc);
    }

    if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size))
    {
        $this->_bcc_array = $bcc;
    }
    else
    {
        $this->_set_header('Bcc', implode(", ", $bcc));
    }

    return $this;
}

// --------------------------------------------------------------------

最佳答案

您能否在您的任何 Controller 索引函数中尝试下面的代码并运行它。

$this->load->library('email');

$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

$this->email->send();

echo $this->email->print_debugger();

关于php - Codeigniter 电子邮件 - 添加 BCC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43810853/

有关php - Codeigniter 电子邮件 - 添加 BCC的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby - 将 Bootstrap Less 添加到 Sinatra - 2

    我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它

  3. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  4. ruby - 可以通过多少种方法将方法添加到 ruby​​ 对象? - 2

    当谈到运行时自省(introspection)和动态代码生成时,我认为ruby​​没有任何竞争对手,可能除了一些lisp方言。前几天,我正在做一些代码练习来探索ruby​​的动态功能,我开始想知道如何向现有对象添加方法。以下是我能想到的3种方法:obj=Object.new#addamethoddirectlydefobj.new_method...end#addamethodindirectlywiththesingletonclassclass这只是冰山一角,因为我还没有探索instance_eval、module_eval和define_method的各种组合。是否有在线/离线资

  5. ruby - 如何在 Ruby 中向现有方法定义添加语句 - 2

    我注意到类定义,如果我打开classMyClass,并在不覆盖的情况下添加一些东西我仍然得到了之前定义的原始方法。添加的新语句扩充了现有语句。但是对于方法定义,我仍然想要与类定义相同的行为,但是当我打开defmy_method时似乎,def中的现有语句和end被覆盖了,我需要重写一遍。那么有什么方法可以使方法定义的行为与定义相同,类似于super,但不一定是子类? 最佳答案 我想您正在寻找alias_method:classAalias_method:old_func,:funcdeffuncold_func#similartoca

  6. ruby-on-rails - 添加回形针新样式不影响旧上传的图像 - 2

    我有带有Logo图像的公司模型has_attached_file:logo我用他们的Logo创建了许多公司。现在,我需要添加新样式has_attached_file:logo,:styles=>{:small=>"30x15>",:medium=>"155x85>"}我是否应该重新上传所有旧数据以重新生成新样式?我不这么认为……或者有什么rake任务可以重新生成样式吗? 最佳答案 参见Thumbnail-Generation.如果rake任务不适合你,你应该能够在控制台中使用一个片段来调用重新处理!关于相关公司

  7. ruby - 我如何添加二进制数据来遏制 POST - 2

    我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_

  8. ruby-on-rails - 在 Ruby on Rails 中添加 boolean 列值 - 2

    我正在开发一个创建网络博客的RubyonRails项目。我希望将一个名为featured的boolean数据库字段添加到Post模型中。该字段应该可以通过我添加的事件管理界面进行编辑。我使用了以下代码,但我什至没有在网站上显示另一列。$railsgeneratemigrationaddFeaturedfeatured:boolean$rakedb:migrate我是RubyonRails的新手,非常感谢任何帮助。我的index.html.erb文件中的相关代码(views):FeaturedPost架构.rb:ActiveRecord::Schema.define(:version=>

  9. ruby - 如何将便捷类方法添加到 ruby​​ 中的 Singleton 类 - 2

    假设我有一个这样的单例类:classSettingsincludeSingletondeftimeout#lazy-loadtimeoutfromconfigfile,orwhateverendend现在,如果我想知道使用什么超时,我需要编写如下内容:Settings.instance.timeout但我宁愿将其缩短为Settings.timeout使这项工作有效的一个明显方法是将设置的实现修改为:classSettingsincludeSingletondefself.timeoutinstance.timeoutenddeftimeout#lazy-loadtimeoutfromc

  10. ruby-on-rails - 向 Rails 3 添加 Ruby 扩展方法的最佳实践? - 2

    我有一个要在我的Rails3项目中使用的数组扩展方法。它应该住在哪里?我有一个应用程序/类,我最初把它放在(array_extensions.rb)中,在我的config/application.rb中我加载路径:config.autoload_paths+=%W(#{Rails.root}/应用程序/类)。但是,当我转到railsconsole时,未加载扩展。是否有一个预定义的位置可以放置我的Rails3扩展方法?或者,一种预先定义的方式来添加它们?我知道Rails有自己的数组扩展方法。我应该将我的添加到active_support/core_ext/array/conversion

随机推荐