PHPMailer异常错误

PHPMailer异常错误,php,codeigniter,phpmailer,Php,Codeigniter,Phpmailer,我已经为发送电子邮件编写了自己的代码点火器模型。直到最近我开始出现这个错误,一切都很好: 致命错误:无法在第2319行的/home/mysite/public_html/subdir/application/libraries/phpmailer/class.phpmailer.php中重新声明类phpmailerException 我正在使用: 编码点火器2 PHPMailer 5.1 我尝试了以下方法来解决此问题: 添加“$mail->SMTPDebug=0”以关闭错误 添加:“$mail

我已经为发送电子邮件编写了自己的代码点火器模型。直到最近我开始出现这个错误,一切都很好:

致命错误:无法在第2319行的/home/mysite/public_html/subdir/application/libraries/phpmailer/class.phpmailer.php中重新声明类phpmailerException

我正在使用:

编码点火器2 PHPMailer 5.1

我尝试了以下方法来解决此问题:

  • 添加“$mail->SMTPDebug=0”以关闭错误
  • 添加:“$mail->MailerDebug=false;”
  • 修改了PHPMailer,使其仅在启用SMTPDebug时显示错误
  • 查找并删除任何回显语句
  • 添加了尝试添加/删除的try/catch块:$mail=new PHPMailer(true)
以下是我的控制器方法(公司/联系人),它调用我的模型(消息\模型):

功能联系人()
{
//进行设置。
$this->options->task='email';
$this->options->change='sent';
$this->options->form_validation='';
$this->options->page_title='Contact Us';
//导入库
include_once('application/libraries/recaptcha/recaptchalib.php');//include recaptcha library。
//recaptcha的密钥,存储在mainconfig文件中。
$this->options->publickey=$this->config->item('recaptcha_public');
$this->options->privatekey=$this->config->item('recaptcha_private');
//表单验证
$this->form_validation->set_error_分隔符(“”,);
$this->form_validation->set_rules('name_field'、'name of problem'、'trim | required | min_length[3]| max_length[100]);
$this->form_validation->set_rules('desc_field'、'Description'、'trim | required |最小长度[10]|最大长度[2000]);
$this->form_validation->set_规则('email_字段','Your email address','trim | required | valid_email');
$this->form_validation->set_rules('recaptcha_response_field'、'captcha field'、'trim | required | callback_check_recaptcha');
//如果有效的话。
如果($this->form\u validation->run())
{
//设置电子邮件内容。
$message=“这是来自“$This->config->item('site_name')”上的联系人表单的消息。”

; $message.=convert_nl($this->input->post($desc_字段)); $message.=“

通过单击此链接回复此人:

”; $options=array('host'=>$this->config->item('email\u host'),//mail.fixilink.com 'username'=>this->config->item('email_username'), “密码”=>$this->config->item('email_password'), 'from_name'=>this->input->post('name_字段'), '到'=>数组($this->config->item('email\u to')=>this->config->item('email\u to')), “抄送”=>$this->config->item('email_cc'), “全名”=>this->input->post('name\u field'), '主题'=>'来自'$this->config->item('site_name').'访问者:'.$this->input->post('name_field')的电子邮件, 'message'=>$message, “word_wrap”=>50, 'format'=>this->config->item('email_format'), 'phpmailer\u folder'=>$this->config->item('phpmailer\u folder')) ); //使用自己的电子邮件类和phpmailer发送电子邮件。 $result=$this->message\u model->send\u email($options); //发送给发件人的第二封电子邮件 //设置电子邮件内容。 $message=“感谢您的询问,我们希望在2个工作日内收到您的回复。同时,请务必在www.facebook.com/autismworksuk上关注我们”; $options=array('host'=>$this->config->item('email\u host'),//mail.fixilink.com 'username'=>this->config->item('email_username'), “密码”=>$this->config->item('email_password'), 'from_name'=>this->input->post('name_字段'), '到'=>this->input->post('email_字段'), “全名”=>this->input->post('name\u field'), 'subject'=>'Email from'.$this->config->item('site_name'), 'message'=>$message, “word_wrap”=>50, 'format'=>this->config->item('email_format'), 'phpmailer\u folder'=>$this->config->item('phpmailer\u folder')) ); //使用自己的电子邮件类和phpmailer发送电子邮件。 $result=$this->message\u model->send\u email($options); //设定结果。 如果($result==-1) $this->session->set_flashdata('result',ucfirst($this->options->task)。“不是”。$this->options->change。“因为数据库错误”。); elseif($result==0) $this->session->set_flashdata('结果','未进行任何更改'); 其他的 $this->session->set_flashdata('result',ucfirst($this->options->task)。'was'.$this->options->change.'successfully'; //重定向到已完成的控制器。 重定向(“已完成”); } //验证失败或首次通过循环。 $this->load->view('company/contact_view.php',$this->options); }
这是我的模型发送电子邮件的方法。它以前可以工作,但没有任何变化,我现在可以想到,我得到一个异常错误:

    function send_email($options=array())
    {
        if(!$this->_required(array('host','username','password','from_name','to','full_name','subject','message'),$options))//check the required options of email and pass aggainst provided $options.
          return false;

        $options = $this->_default(array('word_wrap'=>50,'format'=>'html','charset'=>'utf-8'),$options);

try
{        
  if(isset($options['phpmailer_folder']))
    require($options['phpmailer_folder']."/class.phpmailer.php");
  else
    require("application/libraries/phpmailer/class.phpmailer.php");//Typical CI 2.1 folder.

  $mail = new PHPMailer();
  $mail->MailerDebug = false;

  //Set main fields.
  $mail->SetLanguage("en", 'phpmailer/language/');
  $mail->IsSMTP();// set mailer to use SMTP
  $mail->SMTPDebug  = 0;  

  $mail->Host =     $options['host'];
  $mail->SMTPAuth = TRUE;     // turn on SMTP authentication
  $mail->Username = $options['username'];
  $mail->Password = $options['password'];
  $mail->FromName = $options['from_name'];//WHo is the email from.
  $mail->WordWrap = $options['word_wrap'];// Set word wrap to 50 characters default.
  $mail->Subject =  $options['subject'];
  $mail->Body    =  $options['message'];        
  $mail->CharSet =  $options['charset'];

  //From is the username on the server, not sender email.
  if(isset($options['from']))
    $mail->From = $options['from'];
  else
    $mail->From = $mail->Username;  //Default From email same as smtp user

  //Add reply to.
  if(isset($options['reply_to']))
    $mail->AddReplyTo($options['reply_to'], $options['from']);

  if(isset($options['sender']))
    $mail->Sender = $options['sender'];

  //Add recipients / to field (required)
  if(is_array($options['to']))
  {
    foreach($options['to'] as $to =>$fn)
      $mail->AddAddress($to, $fn);
  }
  else
  {
    $mail->AddAddress($options['to']); //Email address where you wish to receive/collect those emails.
  }

  //Add cc to list if exists. Must be an array
  if(isset($options['cc']))
  {
    if(is_array($options['cc']))
    {
      foreach($options['cc'] as $to =>$fn)
        $mail->AddCC($to, $fn);
    }
    else
    {
      log_message('debug', '---->CC field must be an array for use with Message_Model.');
    }
  }

  //Add bcc to list if exists. Must be an array
  if(isset($options['bcc']))
  {
    if(is_array($options['bcc']))
    {
      foreach($options['bcc'] as $to =>$fn)
        $mail->AddBCC($to, $fn);
    }
    else
    {
      log_message('debug', '---->BCC field must be an array for use with Message_Model.');
    }
  }

  //Alternative text-only body.
  if(isset($options['alt_body']))
    $mail->AltBody=$options['alt_body'];
  else
    $mail->AltBody = htmlspecialchars_decode( strip_tags( $options['message'] ),ENT_QUOTES );//Strip out all html and other chars and convert to plain text.

  //Plain/html format.
  if(isset($options['format']))
  {
    if($options['format']=='html')
      $mail->IsHTML(true);                                  // set email format to HTML
  }     

  //Send email and set result.
  $return['message']='';

  if(!$mail->Send())
  {
   $return['message'].= "Message could not be sent.<br />\n";
   $return['message'].= "Mailer Error: " . $mail->ErrorInfo."\n";
   $return['result'] = 0;
  }
  else
  {
    $return['message'].= "Message has been sent successfully.\n";
    $return['result'] = 1;
  }
}
catch (phpmailerException $e)
{
  log_message('error', '---->PHPMailer error: '.$e->errorMessage() );
}
catch (Exception $e) 
{
  log_message('error', '---->PHPMailer error: '.$e->errorMessage() );
}
        return $return;
    }
函数发送电子邮件($options=array())
{
如果(!$this->\必需(数组('host'、'username'、'password'、'from\u name'、'to'、'full\u name'、'subject'、'message')、$options))//检查电子邮件的必需选项,并传递aggainst提供的$options。
返回false;
$options=$this->\默认值(数组('word\u wrap'=>50,'format'=>'html','charset'=>'utf-8'),$options);
尝试
{        
如果(设置($options['phpmailer_folder']))
需要($options['phpmailer_folder'].“/class.phpmailer.php”);
其他的
require(“application/libraries/phpmailer/class.phpmailer.php”);//典型的CI 2.1文件夹。
$mail=new PHPMailer();
$mail->MailerDebug=false;
//设置主字段。
$mail->SetLanguage(“en”,“phpmailer/language/”);
$mail->IsSMTP();//设置邮件程序以使用SMTP
$mail->SMTPDebug=0;
$mail->Host=$options['Host'];
$mail->SMT
    function send_email($options=array())
    {
        if(!$this->_required(array('host','username','password','from_name','to','full_name','subject','message'),$options))//check the required options of email and pass aggainst provided $options.
          return false;

        $options = $this->_default(array('word_wrap'=>50,'format'=>'html','charset'=>'utf-8'),$options);

try
{        
  if(isset($options['phpmailer_folder']))
    require($options['phpmailer_folder']."/class.phpmailer.php");
  else
    require("application/libraries/phpmailer/class.phpmailer.php");//Typical CI 2.1 folder.

  $mail = new PHPMailer();
  $mail->MailerDebug = false;

  //Set main fields.
  $mail->SetLanguage("en", 'phpmailer/language/');
  $mail->IsSMTP();// set mailer to use SMTP
  $mail->SMTPDebug  = 0;  

  $mail->Host =     $options['host'];
  $mail->SMTPAuth = TRUE;     // turn on SMTP authentication
  $mail->Username = $options['username'];
  $mail->Password = $options['password'];
  $mail->FromName = $options['from_name'];//WHo is the email from.
  $mail->WordWrap = $options['word_wrap'];// Set word wrap to 50 characters default.
  $mail->Subject =  $options['subject'];
  $mail->Body    =  $options['message'];        
  $mail->CharSet =  $options['charset'];

  //From is the username on the server, not sender email.
  if(isset($options['from']))
    $mail->From = $options['from'];
  else
    $mail->From = $mail->Username;  //Default From email same as smtp user

  //Add reply to.
  if(isset($options['reply_to']))
    $mail->AddReplyTo($options['reply_to'], $options['from']);

  if(isset($options['sender']))
    $mail->Sender = $options['sender'];

  //Add recipients / to field (required)
  if(is_array($options['to']))
  {
    foreach($options['to'] as $to =>$fn)
      $mail->AddAddress($to, $fn);
  }
  else
  {
    $mail->AddAddress($options['to']); //Email address where you wish to receive/collect those emails.
  }

  //Add cc to list if exists. Must be an array
  if(isset($options['cc']))
  {
    if(is_array($options['cc']))
    {
      foreach($options['cc'] as $to =>$fn)
        $mail->AddCC($to, $fn);
    }
    else
    {
      log_message('debug', '---->CC field must be an array for use with Message_Model.');
    }
  }

  //Add bcc to list if exists. Must be an array
  if(isset($options['bcc']))
  {
    if(is_array($options['bcc']))
    {
      foreach($options['bcc'] as $to =>$fn)
        $mail->AddBCC($to, $fn);
    }
    else
    {
      log_message('debug', '---->BCC field must be an array for use with Message_Model.');
    }
  }

  //Alternative text-only body.
  if(isset($options['alt_body']))
    $mail->AltBody=$options['alt_body'];
  else
    $mail->AltBody = htmlspecialchars_decode( strip_tags( $options['message'] ),ENT_QUOTES );//Strip out all html and other chars and convert to plain text.

  //Plain/html format.
  if(isset($options['format']))
  {
    if($options['format']=='html')
      $mail->IsHTML(true);                                  // set email format to HTML
  }     

  //Send email and set result.
  $return['message']='';

  if(!$mail->Send())
  {
   $return['message'].= "Message could not be sent.<br />\n";
   $return['message'].= "Mailer Error: " . $mail->ErrorInfo."\n";
   $return['result'] = 0;
  }
  else
  {
    $return['message'].= "Message has been sent successfully.\n";
    $return['result'] = 1;
  }
}
catch (phpmailerException $e)
{
  log_message('error', '---->PHPMailer error: '.$e->errorMessage() );
}
catch (Exception $e) 
{
  log_message('error', '---->PHPMailer error: '.$e->errorMessage() );
}
        return $return;
    }
if (!class_exists("phpmailer")) {
require_once('PHPMailer_5.2.2/class.phpmailer.php');
}