0

我正在尝试在codeigniter框架的控制器类中发送包含以下代码的电子邮件...

    $config['protocol'] = 'sendmail'; 
    $config['mailpath'] = '/usr/sbin/sendmail'; 

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

    $this->email->set_newline("\r\n"); 

    $this->email->from('tanvir@soft-bd.com', 'tanvir@soft-bd.com'); 
    $this->email->to('tanvir064@gmail.com');         
    $this->email->subject('This is an email test');         
    $this->email->message('It is working. Great!'); 

    if ($this->email->send()) { 
        echo "Sent!"; 
        $this->email->print_debugger(); 

    } else { 
        echo "FAILED"; 
        echo $this->email->print_debugger(); 
    }

但显示以下错误

我的代码有什么问题?

4

2 回答 2

0

将此代码粘贴到函数的开头

$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);

这可能对你有帮助!

于 2012-11-20T06:16:51.653 回答
0

您可以尝试使用此代码。我正在从 Gmail smtp 服务器发送邮件......

function sendMail()
    {
        $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'xxx@gmail.com', // change it to yours
      'smtp_pass' => 'xxx', // change it to yours
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );

            $message = $this->load->view('upload_success','',TRUE);
            $this->load->library('email', $config);
          $this->email->set_newline("\r\n");
          $this->email->from('xxx@gmail.com'); // change it to yours
          $this->email->to('yyy@gmail.com');// change it to yours
          $this->email->subject('Resume from JobsBuddy for your Job posting');
          $this->email->message($message);
          if($this->email->send())
         {
          echo 'Email sent.';
         }
         else
        {
         show_error($this->email->print_debugger());
        }

    }
于 2012-11-20T06:07:37.493 回答