邮件无法发送代码点火器

时间:2018-08-08 07:02:38

标签: php codeigniter email

我想从服务器发送邮件到Gmail ID,但收到以下消息:

  

消息:出于安全原因已禁用mail()文件名:   library / Email.php行号:1554

我的代码如下:

$this->load->library(array('session', 'form_validation', 'email')); 
$from_email= "test.mail@domainame.com";
// $pass = "***********";
$to_email = $this->input->post('email');
$subject='Password Reset Request';
$htmlContent = '<p>'.$link.'</p>';
$this->load->library('email'); 
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from($from_email,'Builders'); 
$this->email->to($to_email);
$this->email->subject($subject); 
$this->email->message($htmlContent);    
  if(!$this->email->send()) {
  //success message
  }

我该如何解决?

2 个答案:

答案 0 :(得分:0)

请检查您的配置

$config['protocol'] = 'sendmail'; //check on this, which method you want to use smtp/mail/sendmail?
$config['mailpath'] = '/usr/sbin/sendmail';  
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

请确保发件人地址与您的域相同

答案 1 :(得分:0)

尝试一下。

$emailConfig = [
            'protocol' => 'smtp', 
            'smtp_host' => 'XXXXX', 
            'smtp_port' => 'XXXXX', 
            'smtp_user' => 'XXXXX', 
            'smtp_pass' => 'XXXXX', 
            'mailtype' => 'html', 
            'charset' => 'utf-8'
        ];
        $from = [
            'email' => 'a@b.com',
            'name' => 'ab'
        ];
        $message = 'welcome to our site'; 
        $to = array($email);
        $subject = 'welcome';
        $this->load->library('email', $emailConfig);
        $this->email->set_newline("\r\n");
        $this->email->from($from['email'], $from['name']);
        $this->email->to($to);
        $this->email->subject($subject);
        $this->email->message($message);
        if (!$this->email->send()) {
            show_error($this->email->print_debugger());
        } else {
            echo '<div style="color:green">Email Successfully sent</div>';
        }